How to make an Actor follow my finger
Posted
by
user48352
on Game Development
See other posts from Game Development
or by user48352
Published on 2014-06-21T20:04:53Z
Indexed on
2014/08/22
10:28 UTC
Read the original article
Hit count: 261
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.
© Game Development or respective owner