Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
"moving" and "static" are kinda mutually exclusive, so what you need is some other kind of object if you want to move it. –  Jari Komppa Feb 8 '11 at 8:24
add comment

2 Answers 2

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.

http://entropologygames.wordpress.com/2011/01/28/making-pong-using-farseer-physics-engine/

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

share|improve this answer
    
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. –  user5198 Feb 6 '11 at 10:13
    
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. –  brainydexter Feb 6 '11 at 18:45
add comment

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.

share|improve this answer
    
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 –  user5198 Feb 8 '11 at 13:54
    
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 –  timrwood Feb 12 '11 at 23:02
    
Sorry, to answer the original question in your comment, yes you can move it in ccTouchesMoved. –  timrwood Feb 12 '11 at 23:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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