使用 cocos2d 投掷球,但没有任何物理引擎
我想以滑动速度扔球,但不想使用任何物理引擎。所以请有人建议我如何做到这一点。
谢谢
I want to throw a ball with swipe speed but do not want to use any physic engine. so please can any one suggest me how i do this.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无需显式使用任何物理引擎的一种简单而有效的方法是在更新循环中手动步进球精灵的速度和位置,如欧拉式。
在典型情况下(重力向下),您将在 y 方向上具有非恒定速度,在 x 方向上具有恒定速度,因此代码如下:
然后,当检测到滑动事件时,
A simple yet effective approach without having to explicitly use any physics engine is to step the velocity and position of the ball sprite manually in your update loop, Euler-style.
In the typical case (with downward gravity), you will have non-constant velocity in the y-direction and constant velocity in the x-direction, hence the following code:
Then when a swipe event is detected,
我正在使用抛射运动公式来执行此操作, http://en.wikipedia.org/wiki/Projectile_motion< /a>,以及 cocos 操作。这里有一个可能的方法:
实现一个
CCActionInterval
子类,用于接收弹丸公式参数并更新弹丸位置。在本例中为ProjectileAction
。这些是您需要重写的关键方法:使用滑动手势来识别速度,这将转换为上面等式中球的初始速度和下面的
theVelocity
参数。我把这部分留给你。运行动作。即
我希望这对您有帮助。
问候。
I am using projectile motion formulas to do this, http://en.wikipedia.org/wiki/Projectile_motion, along with cocos actions. Here you have a possible approach:
Implement a
CCActionInterval
subclass that receives the projectile formula parameters and updates the projectile position. In this case,ProjectileAction
. These are the key methods you need to over-ride:Use your swipe gesture to recognize the speed, that will translate to the ball's initial velocity in the equation above and to the
theVelocity
parameter bellow. I leave that part to you.Run the action. i.e.
I hope this helps you.
Regards.