Java ChaseEntity函数在andengine中工作不正常
我需要代码方面的帮助。我想做的是创建一个简单的移动修改器演示,以更好地理解andengine。我所做的是创建一个定向背景精灵,上面有粗体字母,上面写着“上”、“下”、“左”、“右”,这样我就可以跟踪实体的起点和终点。问题在于setChaseEntity函数。似乎每次我运行代码时,我的实体都会卡住。如果你能帮忙,我将不胜感激……谢谢你抽出时间Java ChaseEntity函数在andengine中工作不正常,java,android,eclipse,andengine,game-engine,Java,Android,Eclipse,Andengine,Game Engine,我需要代码方面的帮助。我想做的是创建一个简单的移动修改器演示,以更好地理解andengine。我所做的是创建一个定向背景精灵,上面有粗体字母,上面写着“上”、“下”、“左”、“右”,这样我就可以跟踪实体的起点和终点。问题在于setChaseEntity函数。似乎每次我运行代码时,我的实体都会卡住。如果你能帮忙,我将不胜感激……谢谢你抽出时间 @Override public EngineOptions onCreateEngineOptions() { boundCamera = ne
@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();
}
我认为这是一个措辞很好的问题,但为了确保你可能想更多地说明你的实体在哪里被卡住以及它是如何到达那里的。你必须提供更多的信息,因为在看到代码后,问题并没有变得很清楚。CAMERA\u WIDTH/CAMERA\u HEIGHT的真正价值是什么?如果其大小与精灵背景(800x480)相同,则可能不会注意到矩形移动(由实体修改器引起)和相机移动(由追逐矩形实体引起)。请注意,精灵背景不会“视觉上”移动,当您的相机移动时,请尝试使您的相机尺寸比精灵背景小得多。如果您想使用背景图像内容作为实体或摄影机移动的参考,我建议您使用“交叉图案填充”图像模式。