Android “我的应用程序始终显示”;“你好,世界”;

Android “我的应用程序始终显示”;“你好,世界”;,android,andengine,Android,Andengine,嗨,我是Android开发的新手 我想用AndEngine创建一个简单的游戏。所以我想试一下样品。但是当我将apk文件部署到我的nexus7时。但当我运行应用程序时,它总是在屏幕中央以白色背景显示“Hello World”。但它应该显示具有特定背景颜色的图像 这是我的密码: public class MainActivity extends SimpleBaseGameActivity { private static final float CAMERA_WIDTH = 720; privat

嗨,我是Android开发的新手

我想用AndEngine创建一个简单的游戏。所以我想试一下样品。但是当我将apk文件部署到我的nexus7时。但当我运行应用程序时,它总是在屏幕中央以白色背景显示“Hello World”。但它应该显示具有特定背景颜色的图像

这是我的密码:

public class MainActivity extends SimpleBaseGameActivity {
private static final float CAMERA_WIDTH = 720;
private static final float CAMERA_HEIGHT = 480;
private Camera mCamera;
private BitmapTextureAtlas mBitmapTextureAtlas;
private Engine mEngine;
private TextureRegion mFaceTextureRegion;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public EngineOptions onCreateEngineOptions() {

    this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

    return new EngineOptions(true,
            ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(
                    CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
}

@Override
protected void onCreateResources() {

    this.mBitmapTextureAtlas = new BitmapTextureAtlas(
            mEngine.getTextureManager(), 32, 32,
            TextureOptions.BILINEAR_PREMULTIPLYALPHA);

    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

    this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory
            .createFromAsset(this.mBitmapTextureAtlas, this,
                    "face_box.png", 0, 0);

    getTextureManager().loadTexture(this.mBitmapTextureAtlas);
}

@Override
protected Scene onCreateScene() {

    this.mEngine.registerUpdateHandler(new FPSLogger());
    final Scene scene = new Scene();
    scene.setBackground(new Background(new Color(0, 255, 128)));
    final int centerX = (int) ((CAMERA_WIDTH - this.mFaceTextureRegion
            .getWidth()) / 2);
    final int centerY = (int) ((CAMERA_HEIGHT - this.mFaceTextureRegion
            .getHeight()) / 2);
    final Sprite face = new Sprite(centerX, centerY,
            this.mFaceTextureRegion, new VertexBufferObjectManager());
    scene.attachChild(face);

    return scene;
}
}


我做错了什么?提前感谢。

因为您使用的是AndEngine SimpleBaseGameActivity,所以不需要此功能

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

显示“Hello world”是因为您正在设置内容视图,请删除对onCreate的覆盖,它应该可以工作。

尝试对Hello world进行文本搜索。是否显示
activity\u main.xml
?我敢打赌它包含类似于
@string/hello\u world
的内容。感谢您的回答。你说得对,埃里克。我有一个显示“hello world”的activity_main.xml和一个MainActivity.java。我必须做什么,显示MainActivity.java而不是activity_main.xml?太好了。谢谢。在我使用“BaseGameActivity”之前。这里有一个链接解释了安德林中几个*游戏活动之间的区别(当我开始使用安德林时,我很难理清这一点),删除其中任何一行都会给我一个
不幸的是,应用程序已经停止了
error@MatthewDrill嘿,这个答案是很久以前的。我现在不能推荐AndEngine,但您从哪个GameActivity类继承?