简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM