1
我正在開發一款遊戲,其中有一名玩家通過使用屏幕模擬控制在屏幕上移動。
敵人精靈定期添加到場景中,並向玩家移動。通過使用下面的代碼敵人正在增加。
需要關於AndEngine中Sprite移動的幫助
public void addTarget() {
Random rand = new Random();
float x = (camera.getWidth() + resourcesManager.evilone_region.getWidth());
float minY = resourcesManager.evilone_region.getHeight();
int maxY = (int) (camera.getHeight() - resourcesManager.evilone_region
.getHeight());
int rangeY = (int) (maxY - minY);
float y = rand.nextInt(rangeY) + minY;
target = new AnimatedSprite(x, y, resourcesManager.evilone_region.deepCopy(),vbom){
@Override
protected void preDraw(GLState pGLState, Camera pCamera)
{
super.preDraw(pGLState, pCamera);
pGLState.enableDither();
}
@Override
protected void onManagedUpdate(float pSecondsElapsed)
{
super.onManagedUpdate(pSecondsElapsed);
if(isPlayerMoved){
this.registerEntityModifier(new MoveModifier(2, target.getX(),player.getX(),target.getY(),player.getY()));
}
}
};
attachChild(target);
target.setCullingEnabled(true);
final long[] PLAYER_ANIMATE = new long[] {100, 100, 100};
target.animate(PLAYER_ANIMATE, 0, 2, true);
int minDuration = 2;
int maxDuration = 4;
int rangeDuration = maxDuration - minDuration;
int actualDuration = rand.nextInt(rangeDuration) + minDuration;
mod = new MoveModifier(actualDuration, target.getX(),player.getX(),target.getY(),player.getY());
target.registerEntityModifier(mod.deepCopy());
TargetsToBeAdded.add(target);
}
private void createSpriteSpawnTimeHandler() {
float mEffectSpawnDelay = 1f;
eviloneTimerHandler = new TimerHandler(mEffectSpawnDelay, true,
new ITimerCallback() {
@Override
public void onTimePassed(TimerHandler pTimerHandler) {
if(isPaused){
}else{
//resourcesManager.targetbird.play();
addTarget();
}
}
});
engine.registerUpdateHandler(eviloneTimerHandler);
}
現在的問題是,當我移動與模擬控制我想作爲導致每一個敵人應該改變方向且玩家移動玩家。但是通過使用這個編碼,每個敵人都會朝着第一個被追加的敵人移動,並且他們都朝着這個看起來非常怪異的玩家移動,因爲他們所有的敵人都互相坍塌。
請幫忙。