开发者

Cocos2d Joystick

I have been looking al开发者_如何学Cl over for help on how to make a CCSprite move and rotate with the movement of a virtual joystick. I have tried examples and sample code, but, none have worked for me. If someone could tell me how to implement a joystick into the HelloWorld layer, that would be wonderful. P.S. The joystick does not need to move the sprite with variable velocity, it just needs to move it in a direction at a constant speed. Thanks in advance.


First of all, this is a poorly worded question. Normally I would vote you down for this but for some reason I am not going to today.

You say there is no need for variable velocity, but it needs to move in a direction at a constant speed. I assume then that you need a full 360 degree range. What you do is have a joypad sprite on your layer. When you touch the sprite you calculate the angle of the touch (ignoring distance from center since you don't care about variable velocity). Convert the angle to a CGPoint ( ccpForAngle(CGFloat) is helpful for that ) and then use ccpMult(CGPoint, CGFloat) to decide how fast to move your sprite. Then you can use CCMoveBy to move your sprite.

That's one way of doing it at least.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜