简体   繁体   English

在iPhone的Cocos2D中点按/按住时向上移动精灵

[英]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. 我想知道如何在用户的手指按住屏幕的同时,在Cocos2D中使它向上移动。 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. 谢谢,我认为有必要使用诸如Chipmunk的Box2D之类的物理引擎,但是我不确定如何做到这一点。

-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 . 我有一个不太理想的答案:在较短的时间间隔内(最多0.1秒)设置一个可重复计时器,然后在ccTouchBegan触发计时器,在ccTouchBeganccTouchEnded计时器。 Everytime the timer ticks, move the sprite a short distance. 每当计时器计时时,将精灵移动一小段距离。 the shorter the interval is, the smoother the move will be. 间隔越短,移动就越平滑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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