Jump to content

C++, SDL and Box2D game

- - - - -

  • Please log in to reply
8 replies to this topic

#1
ryaneoghan

ryaneoghan

    Newbie

  • Members
  • Pip
  • 5 posts
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!

#2
TheCompBoy

TheCompBoy

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 272 posts
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.
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/

#3
ryaneoghan

ryaneoghan

    Newbie

  • Members
  • Pip
  • 5 posts
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

#4
TheCompBoy

TheCompBoy

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 272 posts

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
Yes i noticed that there is very little information about Box2D and SDL on the web, But what kind of physics are you intrested in creating?
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/

#5
ryaneoghan

ryaneoghan

    Newbie

  • Members
  • Pip
  • 5 posts
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
TheCompBoy

TheCompBoy

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 272 posts
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
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/

#7
ryaneoghan

ryaneoghan

    Newbie

  • Members
  • Pip
  • 5 posts
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
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
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.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#9
ryaneoghan

ryaneoghan

    Newbie

  • Members
  • Pip
  • 5 posts
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