Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newbie80

macrumors member
Original poster
Mar 2, 2011
51
0
Hi guys,

I have Xcode question.
I would like to know when I touch anywhere on ipad/iphone, the picture on the screen will slowly move to the place that I touched. How do I do that?

I manage to find flash script CS5 for iphone only, but I couldn't find any samples for xcode.

Hope anyone could help me here. Thank you. :)

It looks something like this:
http://asgamer.com/2009/as3-character-movement-following-mouse-with-easing
But I don't want it to follow the pointer wherever I move, when I touch on or click on that place, then the image move to that place and stop.
 
Last edited:
Now how do I make the player stop at the point that I touched?

Code:
@synthesize player;
CGPoint Destination;
CGFloat xamt,yamt;
CGFloat speed = 50;


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [[event allTouches] anyObject];
	CGPoint location = [touch locationInView:self.view];
    
    Destination = location;
    xamt = ((Destination.x - player.center.x) / speed);
	yamt = ((Destination.y - player.center.y) / speed);
    
    [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
    
}

- (void)onTimer{
player.center = CGPointMake(player.center.x+xamt, player.center.y+yamt);
    if (player.center.x > 320 || player.center.x < 0) {
        xamt = -xamt;
    }
    if (player.center.y > 480 || player.center.y < 0) {
        yamt = -yamt;
    }
   
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.