嗨,我是Android開發新手。我的應用程序總是顯示「Hello World」
我想用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;
}
}
我在做什麼錯?提前致謝。
嘗試對Hello World進行文本搜索。 – Isaac
介意顯示'activity_main.xml'?我敢打賭它包含類似於@ string/hello_world'的東西。 – Eric
感謝您的回答。你是對的Eric。我有一個activity_main.xml顯示「hello world」和一個MainActivity.java。我需要做些什麼來顯示MainActivity.java而不是activity_main.xml? –