Author Topic: Moving an object to a specific spot  (Read 1169 times)

JohnR

  • Guest
Moving an object to a specific spot
« on: February 13, 2014, 07:57:41 am »
How can I make an object move to a particular location by clicking on it and touching the location it's going to?

DevPet

  • Guest
Re: Moving an object to a specific spot
« Reply #1 on: February 24, 2014, 06:14:54 am »
Do you want to drag it to the final location or do you want the object to move on his own toward the location?

First Case (simpler):
int objectView = ViewAdd(objectImage,startX,startY,OnTouch,1);

and then
int OnTouch(int id, int event, int x, int y)
{
if (event == 2) ViewSetxy(objectView,x,y);
return 0;
}

SecondCase
You must have a touch area where you can pin the end point, ex:
int touchArea = TouchAdd(0,0,320,480,OnTouch,1):

and then
int OnTouch(int id, int event, int x, int y)
{
if (event == 1) {
aimX = x;aimY = y;
time = 0;
angle = ...//calculate the angle between the current point and the aim point, email me for further details
return 0;
}

and then
onTimer()
{
time ++;
newX = startX + cos(angle);
newY = startY + sin(angle);
viewSetxy(objectView,newX,newY);
}

this is very primitive, feel free to ask for smarter code.