Reputation: 17169
I have a sprite in my iPhone game, how can make it so that that sprite moves to the location of my touch? It needs to transition there, not just switch immediately. My sprite is a CCSprite from cocos2d.
Upvotes: 2
Views: 963
Reputation: 1939
I hope you are already able to detect the touch location..
Assuming you already have the touch location, by using CCMoveTo:
id move = [CCMoveTo actionWithDuration:duration position:touchLocation];
[spr runAction:move];
Hope it helps.. =)
Upvotes: 0
Reputation: 6405
Assuming you want to implement this using UIKit's animation support (and your sprite is implemented as a view), this is one way of doing it.
on a touch event, get the location of the touch, and based on the current location of your sprite, determine how long it would take for your sprite to get there
inside an animation block, change the frame of your sprite view to the touch location, and also specify the duration and other options you want.
Apple's 'View Programming Guide' will basically explains everything you need to know to take this approach.
Upvotes: 1