【发布时间】:2014-02-18 15:26:15
【问题描述】:
我决定开始学习游戏编程,并选择 cocos2d V3 作为我的第一个 2d 游戏引擎。据我了解,cocos2d-iphone v3自带花栗鼠作为物理引擎。
我设法创建了一个纵向应用程序,该应用程序在屏幕的从左到右有一个平台,上面有一个对象(框)。
Platform 和 Box 是带有附加 CCPhysicsBody 的 CCSprite。
当我触摸屏幕右侧时,我想将这个框推到左边,当我触摸屏幕左侧时,我想把它推到右边。盒子不应该跳,而只是向左或向右推。
通过查看 cocos2d v3 文档,我发现了这些方法:CCPhyicsBody
- (void)applyAngularImpulse:(CGFloat)impulse
- (void)applyForce:(CGPoint)force
- (void)applyForce:(CGPoint)force atLocalPoint:(CGPoint)point
- (void)applyForce:(CGPoint)force atWorldPoint:(CGPoint)point
- (void)applyImpulse:(CGPoint)impulse
- (void)applyImpulse:(CGPoint)impulse atLocalPoint:(CGPoint)point
- (void)applyImpulse:(CGPoint)impulse atWorldPoint:(CGPoint)point
- (void)applyTorque:(CGFloat)torque
通过使用 applyImpulse 并传递触摸位置 CGPoint,我设法使框跳了一点。但我的要求是我的盒子只向左或向右移动而不跳跃。
有人可以向我解释我应该使用哪种方法吗?该方法的参数应该是什么?
提前感谢您的帮助!
【问题讨论】:
标签: objective-c cocos2d-iphone chipmunk