Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
763 views
in Technique[技术] by (71.8m points)

iphone - Simple gun in cocos2d+box2d game

I'm newbie in box2d. Can you help me? I want to make gun (touch, move, stopped, ball flew). I make detection and rotation of gun, but I can't make popping of ball. How can I count velocity, which I need to set to the ball? Thank you very much

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The easiest way is to look at the direction the gun is pointing when you define the body, and use GetWorldVector to see how it has changed. For example if the gun is pointing directly upwards when you create the body, this would be the direction (0,1). Then you can use GetWorldVector at any time to get the current direction of that vector in world coordinates:

body->GetWorldVector( b2Vec2(0,1) );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...