How to make an Actor follow my finger
- by user48352
I'm back with another question that may be really simple.
I've a texture drawn on my spritebatch and I'm making it move up or down (y-axis only) with Libgdx's Input Handler: touchDown and touchUp.
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
myWhale.touchDownY = screenY;
myWhale.isTouched = true;
return true;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
myWhale.isTouched = false;
return false;
}
myWhale is an object from Whale Class where I move my texture position:
public void update(float delta) {
this.delta = delta;
if(isTouched){
dragWhale();
}
}
public void dragWhale() {
if(Gdx.input.getY(0) - touchDownY < 0){
if(Gdx.input.getY(0)<position.y+height/2){
position.y = position.y - velocidad*delta;
}
}
else{
if(Gdx.input.getY(0)>position.y+height/2){
position.y = position.y + velocidad*delta;
}
}
}
So the object moves to the center of the position where the person is pressing his/her finger and most of the time it works fine but the object seems to take about half a second to move up or down and sometimes when I press my finger it wont move.
Maybe there's another simplier way to do this. I'd highly appreciate if someone points me on the right direction.