我使用AndEngine 來實現sprite更換圖片。使用這個sprite可以在屏幕之間來回拖動圖片。
所以我想實現的是當用戶觸摸屏幕的任何一個地方,或者向上或向下移動,可以使sprite彈出圖片。
使用AndEngine如何處理這個問題呢?
非常感謝!
下面的方法應該可以:
@Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
if(pSceneTouchEvent.isActionDown()) { //Jump only if the user tapped, not moved his finger or something
final Entity playerEntity = ...;//Get player entity here.
final float jumpDuration = 2;
final float startX = playerEntity.getX();
final float jumpHeight = 100;
final MoveYModifier moveUpModifier = new MoveYModifier(jumpDuration / 2, startX, startX - jumpHeight); // - since we want the sprite to go up.
final MoveYModifier moveDownModifier = new MoveYModifier(jumpDuration / 2, startX + jumpHeight, startX);
final SequenceEntityModifier modifier = new SequenceEntityModifier(moveUpModifier, moveDownModifier);
playerEntity.registerEntityModifier(modifier);
return true;
}
return false;
}