gần đây tôi bắt đầu làm việc trên AndEngine. Khó tìm tài liệu cập nhật/tài liệu trợ giúp về vấn đề này. Tôi đang cố gắng đặt hình nền sau khi xem qua các ví dụ & mã nguồn. Nhưng vì lý do nào đó màn hình vẫn trống. Tôi không thể tìm thấy bất kỳ thông tin hữu ích nào liên quan đến điều này. Đây là mã:Hình nền AndEngine
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
}
}
Xin chào, tôi đánh giá cao phản hồi nhưng tôi đã thử điều đó và nó không giúp ích gì. Tui bỏ lỡ điều gì vậy? Ý tưởng khác nhau? – Mob
Tin tốt cuối cùng đã nhận được nó. như có thể thấy trong mã đính kèm phía trên phương thức onCreate (..) là ghi đè bố cục. tôi đã xóa phương thức và nó đang hoạt động ngay bây giờ. – Mob
Vâng, vâng, bạn không muốn có điều đó :-) – bos