Search code examples
iphonecocos2d-iphonespritemovetap

Move sprite up while tapping/holding in Cocos2D for iPhone


I was wondering how to have it in Cocos2D to make a sprite move up, while the user's finger is being held on the screen. I have a mechanism in place that does so, but only moves the sprite once.

Is it possible to have the sprite move up while the finger is holding on the screen?

Also, even though it's not necessary, if you could make it so when the user isn't holding on the screen, the sprite goes down.

Thanks, I think that a physics engine such as Box2D of Chipmunk is necessary, but I'm not sure how to do this.

-Soule


Solution

  • I have a not so perfect answer: set up a repeatable timer with a short interval, at most 0.1 second, then fire the timer in ccTouchBegan, invalid the timer in ccTouchEnded. Everytime the timer ticks, move the sprite a short distance. the shorter the interval is, the smoother the move will be.