iphone - make object move from 1 point to another at a custom speed -


i made app there object moves towards moving point time - why didn't use animated function. problem made function:

cgpoint center = self.im.center; // "i" cgpoint, im imageview. if (!cgpointequaltopoint(self.im.center, i)) {     = (i.y-center.y)/(i.x-center.x);     //y = a*x+b - linear function in math     b = (center.y-(a*center.x));     if (i.y>center.y) {         self.im.center = cgpointmake(((center.y+1)-b)/a, center.y+1);     }     else     {         self.im.center = cgpointmake(((center.y-1)-b)/a, center.y-1);     } } 

the problem closer functions becoming straight horizontal line faster because change x axis means if add 1 y change x bigger means move faster..

if there way glad try if know other ways tell me!

managed find different solution

cgpoint center = self.im.center;//im = image view x = center.x;//starting point y = center.y;//starting point double distance = sqrtf(powf(i.x - x, 2) + powf(i.y - y, 2));// = cgpoint (ending point) float speedx = (2 * (i.x - x)) / distance;//(the 2 speed) float speedy = (2 * (i.y - y)) / distance;//(the 2 speed) self.im.center = cgpointmake(center.x+speedx, center.y+speedy);//im = image view 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -