在 iPhone 版 Cocos2D 中点击/按住时向上移动精灵
我想知道如何在 Cocos2D 中让精灵向上移动,同时用户的手指按住屏幕。我有一个机制可以做到这一点,但只移动精灵一次。
当手指按住屏幕时,是否可以让精灵向上移动?
另外,即使没有必要,如果您可以做到这一点,那么当用户没有按住屏幕时,精灵就会下降。
谢谢,我认为像Chimpunk的Box2D这样的物理引擎是必要的,但我不知道如何做到这一点。
-苏尔
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有一个不太完美的答案:
设置一个可重复的定时器,间隔较短,最多0.1秒,然后在
ccTouchBegan
中触发定时器,在ccTouchEnded
中使定时器无效。每次计时器滴答作响时,将精灵移动一小段距离。间隔越短,移动越平滑。
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 inccTouchEnded
. Everytime the timer ticks, move the sprite a short distance.the shorter the interval is, the smoother the move will be.