Hello everyone, I'm in the process of trying to get some simple physics working in Box2D using SDL for rendering.
My question is this: how do I actually visualise the physics being done by Box2D using SDL? Is it a case of "grafting" bitmap graphics onto objects into the Box2D world?
Can anyone provide me with a simple code example? There is a shocking lack of tutorials online covering this so hopefully someone may be able to help.
thanks!
8 replies to this topic
#1
Posted 04 January 2012 - 09:43 AM
|
|
|
#2
Posted 04 January 2012 - 10:22 PM
Your game obects would probaly have to create both SDL(Example: SDL_Surface*) and Box2D(Example: b2Body*) as structure.
Each update you use the box2D's step (Example: b2World::Step()) and for drawing you use SDL (SDL_BlitSurface(), SDL_Flip(), etc)
I can't help you much more, I've never worked with box2D. Hope it helped atleast a little.
Each update you use the box2D's step (Example: b2World::Step()) and for drawing you use SDL (SDL_BlitSurface(), SDL_Flip(), etc)
I can't help you much more, I've never worked with box2D. Hope it helped atleast a little.
Think my post we're usefull? Please take your time and press the Like button at my post, Big Thanks!
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/
#3
Posted 05 January 2012 - 02:57 AM
Hi,
thanks for your reply, I will give your advice a try and see how I get on, there is just very little help I have noticed with box2d and sdl, but thank you for helping
thanks for your reply, I will give your advice a try and see how I get on, there is just very little help I have noticed with box2d and sdl, but thank you for helping
#4
Posted 05 January 2012 - 03:01 AM
ryaneoghan said:
Hi,
thanks for your reply, I will give your advice a try and see how I get on, there is just very little help I have noticed with box2d and sdl, but thank you for helping
thanks for your reply, I will give your advice a try and see how I get on, there is just very little help I have noticed with box2d and sdl, but thank you for helping
Can you tell me more about your game, maybe i can help a little bit more.
Think my post we're usefull? Please take your time and press the Like button at my post, Big Thanks!
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/
#5
Posted 05 January 2012 - 08:28 AM
Yeah I was surprised with how little there is. I am just trying to create a game similar to the likes of fragger, a 2D game where I would have a sprite that would throw bombs and try destroy NPC's, I just wanted to try create a fun game with simple (enough) physics and nice animation but am finding it very difficult to find any help or tutorials to even get me started. At the moment I am just trying to figure out how Box2D physics would work with SDL's loading of say a PNG Image, am really struggling, cannot even find a simple bit of code to use or show me how it works? Any help would be great
#6
Posted 05 January 2012 - 08:38 AM
Lets say you use box2d to store the cordinates of the grenade your soldier throws in fragger.. You could use those cordinates in the SDL_Surface* you use for your grenade..
Thats how i mean, Have you worked with SDL before?
SDL_Surface*: SDL_Surface
SDL_Rect: SDL_Rect
Thats how i mean, Have you worked with SDL before?
SDL_Surface*: SDL_Surface
SDL_Rect: SDL_Rect
Think my post we're usefull? Please take your time and press the Like button at my post, Big Thanks!
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/
#7
Posted 05 January 2012 - 09:40 AM
I used SDL before but never with physics, thats is the major problem I am having is understanding how to draw a sprite and redraw using some physics calculations or as you said in the above post, I just cant seem to find a simple example of code that would allow show me exactly how to get even started, am not looking for an example of my game but just even something thats shows me how to get started? :crying:
#8
Posted 05 January 2012 - 10:30 AM
You would create a class, lets say Grenade, and add methods and properties to it. Methods could be draw, do_math and such, and properties would be sprite (SDL_Surface), position in the world and such.
Check out box2d manual, there are some code snippets along with comments to get you started.
Check out box2d manual, there are some code snippets along with comments to get you started.
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#9
Posted 05 January 2012 - 12:03 PM
ok I will have a look into that now and see how I get on, thanks for your help
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









