I am having problems working with Androids Motion event system, I'm trying to implement a simple control system where pushing down on the left side of a screen decreases a Sprites y velocity whilst pushing down on the right hand side of a screen increases a Sprites velocity.
____________________
| | |
|click | click|
|down Sprite up|
|_________|_________|
if nothing is pressed velocity is reset back to 0.
I have not been successful with this to work so I've temporarily resorted to a different system, below is the code I have.
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
int action = event.getAction();
if(action == MotionEvent.ACTION_DOWN){
if(x < this.getWidth()/2)
this.fish.vy = 2;
if(x > this.getWidth()/2)
this.fish.vy = -2;
}
if(action == MotionEvent.ACTION_UP){
this.fish.vy=0;
}
return false;
}