This should work:
@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; }
Keep in mind that if you use this, whenever there is an ACTION_DOWN event, you can skip some other event handlers for this (for example, if you have on-screen buttons, they will never handle the event).
The way to handle it is to use any other objects that you want to receive touch events as touch areas for your scene, Scene.registerTouchArea(ITouchArea) does this. Sprite and AnimatedSprite implement ITouchArea so you can use them.
When a Scene receives a TouchEvent handler, it will first resolve all ITouchArea entries you registered, and then, if they have not been destroyed, it will try to use the onSceneTouchEvenet method.
source share