How to move character with touch on Android -


i'm trying make game control character via touch on android devices.

the player have 2 option of movement.

1- when touch touch screen , move finger, game object should move finger's location , follow finger move it.

2-when left finger , touch in place character go position touch finger

please help

thanks in advance

show me code, preferably ontouch, using surfaceview?

we can thats little vague.

heres need. need capture x , y coordinates, presumably in case in few different states, i.e.: when first touched, when touched while moving, , or touch up:

 @override   public boolean ontouchevent(motionevent event) {    // todo auto-generated method stub      tx = event.getx();         ty = event.gety();     int action = event.getaction();    switch(action){    case motionevent.action_down:          tx = event.getx();             ty = event.gety();         obj.touchdown(tx,ty);     break;    case motionevent.action_move:        tx = event.getx();         ty = event.gety();         obj.touchmove(tx,ty);       break;    case motionevent.action_up:     obj.touchrelease(tx,ty);     break;    case motionevent.action_cancel:      break;    case motionevent.action_outside:      break;    default:    }    return true; //processed   } 

then need implement these methods in object class respond. pathing point touched point simple enough once play around it

in object class above code in surfaceview

public void touchmove(float tx,float ty){ obj.x=tx; obj.y=ty;  } 

this drag item finger while touch.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -