PDA

View Full Version : Need help - xcode: mouse follow easing




newbie80
Apr 1, 2011, 01:42 AM
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.



newbie80
Apr 4, 2011, 02:16 AM
Now how do I make the player stop at the point that I touched?


@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;
}

}

dejo
Apr 4, 2011, 09:31 AM
Have you looked at Apple's MoveMe (http://developer.apple.com/library/ios/#samplecode/MoveMe/Introduction/Intro.html) sample app and the very excellent Creating an iPhone Application (http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/Creating_an_iPhone_App/_index.html) article that is based on it?

newbie80
Apr 8, 2011, 02:27 AM
Have you looked at Apple's MoveMe (http://developer.apple.com/library/ios/#samplecode/MoveMe/Introduction/Intro.html) sample app and the very excellent Creating an iPhone Application (http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/Creating_an_iPhone_App/_index.html) article that is based on it?
Thanks for the link.:)