【发布时间】:2011-11-29 03:06:12
【问题描述】:
我是安卓游戏开发的新手。我一直在尝试游戏开发的示例,但有些无法理解 android 中空点异常的原因。
public void onLoadResources() {
this.mBitmapTextureAtlas = new BitmapTextureAtlas(512, 512,
TextureOptions.BILINEAR_PREMULTIPLYALPHA);
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
this.mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory
.createFromAsset(this.mBitmapTextureAtlas, this, "Player.png",
0, 0);
this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
final int PlayerX = (int)(mCamera.getWidth() / 2);
final int PlayerY = (int) ((mCamera.getHeight() - mPlayerTextureRegion
.getHeight()) / 2);
this.player = new Sprite(PlayerX, PlayerY, this.mPlayerTextureRegion);
this.player.setScale(2);
this.mMainScene.attachChild(this.player);
}
最后一行"this.mMainScene.attachChild(this.player);" 导致空点异常,即使所有内容都已初始化。评论此行后一切正常,但显示没有精灵。
这里是初始化mMainScene的代码
public Scene onLoadScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
this.mMainScene = new Scene();
this.mMainScene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));
return mMainScene;
}
【问题讨论】:
标签: java android nullpointerexception