how can i move static box2d sprites. i have tried this tutorial from . http://www.raywenderlich.com/475/how-to-create-a-simple-breakout-game-with-box2d-and-cocos2d-tutorial-part-12.

I managed to add another "paddle" object with box2d body, but i can seam to be able to make the code to move the second "paddle" body. Can anyone direct me how to do it?

Is there a way to move a "b2_staticBody" box 2d object? i have tried, but i can only move it when i use "b2_dynamicBody" if i used "b2_staticBody" i can move it at all.

  • \$\begingroup\$ "moving" and "static" are kinda mutually exclusive, so what you need is some other kind of object if you want to move it. \$\endgroup\$ – Jari Komppa Feb 8 '11 at 8:24

You want to use a dynamic body, if you want bodies to move in your physics. That is, the nature of bodies in box2d. You make a dynamic body, and apply impulse or force to it in the direction you want it to move.

I recently wrote a very basic tutorial to create a pong game using farseer physics engine (which is a c# port of box2d), so the same things would apply.


Also, it would help to know what kind of a game are you making ?

| improve this answer | |
  • \$\begingroup\$ hi, my game will a little like a puzzle. There will be a ball, and another sprite/object. This object can be moved with a touch, and once placed i a suitable location that object should be permanent there. When i launch the ball, this ball will start to deflecting from this object to the next destination/location. Is there another method i can used for the sprite/object to be able to bounce/deflect the ball. Sorry im still new to game programming. \$\endgroup\$ – user5198 Feb 6 '11 at 10:13
  • \$\begingroup\$ If you're using box2d, your ball should be a dynamic object. I'd recommend making a simple (static) box. ApplyLinearImpulse(..) to the ball in the direction where the box is placed and box2d should handle the ball to bounce/deflect of the box. Also, don't forget to set the 'restitution' for the ball and box. \$\endgroup\$ – brainydexter Feb 6 '11 at 18:45

I'm not sure which version you are working with, but version 2.1.0 has 'kinematic bodies'.

Instead of bodyDef.type = b2_dynamicBody; you would put bodyDef.type = b2_kinematicBody;.

They are sort of like static bodies, only you can move them. They only move how you tell them to, so they aren't affected by collisions or other forces (like gravity).

From the box2d docs at http://www.box2d.org/manual.html

A kinematic body moves under simulation according to its velocity. Kinematic bodies do not respond to forces. They can be moved manually by the user, but normally a kinematic body is moved by setting its velocity. A kinematic body behaves as if it has infinite mass, however, Box2D stores zero for the mass and the inverse mass. Kinematic bodies do not collide with other static or kinematic bodies.

| improve this answer | |
  • \$\begingroup\$ Hi, can i confirm again, the b2_kinematicBody i can used it in ccTouchesMoved right? Do i need to use any mouse node like in example tutorial raywenderlich.com/475/…. Sorry im really new in Iphone SDK programming \$\endgroup\$ – user5198 Feb 8 '11 at 13:54
  • \$\begingroup\$ It might not be best to use a mousejoint to move a kinematic body. Check out this thread for a good discussion about this. cocos2d-iphone.org/forum/topic/7599 \$\endgroup\$ – timrwood Feb 12 '11 at 23:02
  • \$\begingroup\$ Sorry, to answer the original question in your comment, yes you can move it in ccTouchesMoved. \$\endgroup\$ – timrwood Feb 12 '11 at 23:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.