CCSprite following a sequence of CGPoints
Posted
by pgb
on Stack Overflow
See other posts from Stack Overflow
or by pgb
Published on 2010-04-08T22:01:16Z
Indexed on
2010/04/08
22:03 UTC
Read the original article
Hit count: 548
iphone
|cocos2d-iphone
I'm developing a line drawing game, similar to Flight Control, Harbor Master, and others in the appstore, using Cocos2D.
For this game, I need a CCSprite to follow a line that the user has drawn. I'm storing a sequence of CGPoint
structs in an NSArray
, based on the points I get in the touchesBegin
and touchesMoved
messages. I now have the problem of how to make my sprite follow them.
I have a tick method, that is called at the framerate speed. In that tick method, based on the speed and current position of the sprite, I need to calculate its next position. Is there any standard way to achieve this?
My current approach is calculate the line between the last "reference point" and the next one, and calculate the next point in that line. The problem I have is when the sprite "turns" (moves from one segment of the line to another).
Any hint will be greatly appreciated.
© Stack Overflow or respective owner