I am using angengine to create a project for school.
I have a Sprite that i allow the user to touch and move.
The sprite is on top of the tiled map in my project.
What i would like to do is create a way so that the user cannot move the sprite up or down. Only side to side
Here is what i am using so far to allow the user to move the sprite anywhere they choose.
player = new Sprite(PlayerX, PlayerY, mHippoTextureRegion){
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2, pSceneTouchEvent.getY() - this.getHeight() / 2);
return true;
}
};
Any ideas or help will be greatly appreciated.
Simply don’t use the Y value from the touch event:
Or if
Spritedoesn’t have asetXmethod but does have agetYmethod: