ErlendHL
1313 posts
|
Hey. I figured out I need to implement Box2D in my game. So I have this test project first when I basically try to draw a ground and a ball that should fall down…
I wrote 120 lines of code to add those and draw them. But they don’t move at all. I’ll post my code to pastebin: http://pastebin.com/VVmXugyP
You should look at the init funciton and the update function. Drawing works. It’s just that I’d expect that the ball would fall. It stays still in the air.
Any help would be much appreciated!
|
DPbrad
1197 posts
|
circleBodyDef.type = b2Body.b2_dynamicBody
|
ErlendHL
1313 posts
|
Originally posted by DPbrad:
circleBodyDef.type = b2Body.b2_dynamicBody
Couldn’t find type in circleBodyDef and neither b2_dynamicBody in b2Body, but this is the closest I could come:
circleDef.type = b2Body.e_dynamicType;
And it threw Error #1009 (null object reference) from inside the b2Body class ._.
Using Box2D 2.02 btw.
|
DPbrad
1197 posts
|
You may need to call SetMassFromShapes on your circle b2Body then if your using 2.0.2…
EDIT: After line 56 in your pastebin code.
|
UnknownGuardian
8140 posts
|
Random note would be I think your gravity vector is also wrong. -10.0 will make it float to the top I think.
|
player_03
1249 posts
|
Originally posted by ErlendHL:
Couldn’t find type in circleBodyDef
Are you using box2Dflash?
I checked, and type is defined on line 67 of b2BodyDef. Additionally, SetType() is defined on line 897 of b2Body.
For some reason, neither one appears in the online documentation, but they’re definitely there.
|
ErlendHL
1313 posts
|
Thanks all!
I changed the init function to this
It now looks like this. I think the movement looks really crappy, and when it finally lands on the ground, it keeps ‘shaking’…
|
DPbrad
1197 posts
|
Originally posted by player_03:
Originally posted by ErlendHL:
Couldn’t find type in circleBodyDef
Are you using box2Dflash?
I checked, and type is defined on line 67 of b2BodyDef. Additionally, SetType() is defined on line 897 of b2Body.
For some reason, neither one appears in the online documentation, but they’re definitely there.
It is in Box2D 2.1, but Erlend is using the old version and I don’t think that “type” property of a “b2BodyDef” was implemented in the old version.
Regarding the shakiness Erlend, I would recommend just using the newer Box2D (2.1a). It contains a lot of fixes over the old version and you dont require as many lines of code for the same functionality you desire.
|