我的代码需要帮助。我想要做的是创建一个简单的移动修改器演示,以尝试更好地理解andengine。我所做的是创建一个方向背景精灵,它有粗体字母,分别是顶部,底部,左侧,右侧,所以我可以跟踪我的实体从哪里开始以及它最终到达的位置。问题是setChaseEntity函数。似乎每次我运行代码时我的实体都会卡住。如果你能提供帮助,我将不胜感激....感谢您的时间....
@Override
public EngineOptions onCreateEngineOptions() {
boundCamera = new BoundCamera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
boundCamera.setBounds(0, 0, CAMERA_WIDTH * 4, CAMERA_HEIGHT * 4);
return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), boundCamera);
}
@Override
public void onCreateResources(
OnCreateResourcesCallback pOnCreateResourcesCallback)
throws Exception {
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(),800,480);
this.mDirection = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas,this,"direction.png",0,0);
this.mBitmapTextureAtlas.load();
pOnCreateResourcesCallback.onCreateResourcesFinished();
}
@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
throws Exception {
this.mEngine.registerUpdateHandler(new FPSLogger());
mScene = new Scene();
Sprite background = new Sprite(0,0,mDirection, mEngine.getVertexBufferObjectManager());
SpriteBackground direction = new SpriteBackground(255,255,255,background);
mScene.setBackground(direction);
pOnCreateSceneCallback.onCreateSceneFinished(mScene);
}
@Override
public void onPopulateScene(Scene pScene,
OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
final int rectangleDimensions = 80;
final int initialPosition = (int) (rectangleDimensions * 0.5f);
Rectangle rectangle = new Rectangle(initialPosition, initialPosition, rectangleDimensions, rectangleDimensions, mEngine.getVertexBufferObjectManager());
rectangle.setColor(Color.RED);
mScene.attachChild(rectangle);
this.boundCamera.setChaseEntity(rectangle);
final float duration = 3;
final float fromX = initialPosition;
final float toX = CAMERA_WIDTH - rectangleDimensions * 0.5f;
final float fromY = initialPosition;
final float toY = CAMERA_HEIGHT - rectangleDimensions * 0.5f;
MoveModifier moveModifier = new MoveModifier(duration, fromX, fromY, toX, toY);
rectangle.registerEntityModifier(moveModifier);
pOnPopulateSceneCallback.onPopulateSceneFinished();
}