gpt4 book ai didi

android - AndEngine背景图片

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:40:15 25 4
gpt4 key购买 nike

最近我开始研究 AndEngine。在这方面很难找到最新的文档/帮助 Material 。在查看示例和源代码后,我正在尝试设置背景图像。但由于某种原因,屏幕仍然是空白的。我找不到与此相关的任何有用信息。这是代码:

public class AndEngineActivity extends BaseGameActivity {

private static final int CAMERA_WIDTH = 720;
private static final int CAMERA_HEIGHT = 480;

private Camera mCamera;
private TextureRegion mBgTexture;
private BitmapTextureAtlas mBackgroundTexture;


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

@Override
public Engine onLoadEngine() {
// TODO Auto-generated method stub
this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));
}

@Override
public void onLoadResources() {
// TODO Auto-generated method stub
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

this.mBackgroundTexture = new BitmapTextureAtlas(1024, 1024, TextureOptions.DEFAULT);
mBgTexture = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBackgroundTexture, this, "background.png", 0, 0);

this.mEngine.getTextureManager().loadTextures(this.mBackgroundTexture);

}

@Override
public Scene onLoadScene() {

this.mEngine.registerUpdateHandler(new FPSLogger());

final Scene scene = new Scene();
final int centerX = (CAMERA_WIDTH -
mBgTexture.getWidth()) / 2; final int centerY = (CAMERA_HEIGHT -
mBgTexture.getHeight()) / 2;
SpriteBackground bg = new SpriteBackground(new Sprite(centerX, centerY, mBgTexture));
scene.setBackground(bg);

return scene;
}

@Override
public void onLoadComplete() {
// TODO Auto-generated method stub

}
}

最佳答案

你需要删除:

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

关于android - AndEngine背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9679921/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com