我在Android和游戏编程方面非常陌生。我想用[Dijkstra算法]做一个迷宫游戏。我想在TMX Map上创建一个由DigitanOnScreenControl移动的AnimatedSprite。但是有麻烦,AnimatedSprite仍然可以克服我制造的障碍。 那么,如何为AnimatedSprite创建一个在ITiledMap上面运行的方法?
这是AnimatedSprite:
musuh = new AnimatedSprite(90, 90, this.mMusuhTextureRegion);
final PhysicsHandler physicsHandler2 = new PhysicsHandler(musuh);
musuh.registerUpdateHandler(physicsHandler2);
scene.attachChild(musuh);
这是DigitalOnScreenControl:
this.mDigitalOnScreenControl = new DigitalOnScreenControl(0, CAMERA_HEIGHT - this.mOnScreenControlBaseTextureRegion.getHeight(), this.mBoundChaseCamera,
this.mOnScreenControlBaseTextureRegion, this.mOnScreenControlKnobTextureRegion, 0.1f, new IOnScreenControlListener() {
int TileNumber = 1;
@Override
public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl,
final float pValueX, final float pValueY) {
physicsHandler2.setVelocity(pValueX * 100, pValueY * 100);
// Set the correct walking animation
if (pValueY == 1){
// Up
if (playerDirection != PlayerDirection.UP){
musuh.animate(ANIMATE_DURATION, 0, 2, false);
playerDirection = PlayerDirection.UP;
}
}else if (pValueY == -1){
// Down
if (playerDirection != PlayerDirection.DOWN){
musuh.animate(ANIMATE_DURATION, 9, 11, false);
playerDirection = PlayerDirection.DOWN;
}
}else if (pValueX == -1){
// Left
if (playerDirection != PlayerDirection.LEFT){
musuh.animate(ANIMATE_DURATION, 3, 5, false);
playerDirection = PlayerDirection.LEFT;
}
}else if (pValueX == 1){
// Right
if (playerDirection != PlayerDirection.RIGHT){
musuh.animate(ANIMATE_DURATION, 6, 8, false);
playerDirection = PlayerDirection.RIGHT;
}
}else{
if (musuh.isAnimationRunning()){
musuh.stopAnimation();
playerDirection = PlayerDirection.NONE;
}
}
}
});