Sign in to follow this  
Shenzo

Searching for a good tutorial [SFML]

Recommended Posts

Shenzo    107

Hi everyone , i'm searching for a SFML 2.1 tutorial smile.png.
I searched a lot for a complete tutorial to create a 2D platformer with SFML (C++) but i don't find anything i find only some part like load a picture play a music etc ...  but nothing about collision or how a 2D game works :/

Edited by Shenzo

Share this post


Link to post
Share on other sites
alvaro    21247
Tutorials are a quick method to get you started with a language or a library. Putting together a platformer is probably too complex a project to cover in a tutorial.

There are still some good resources you can use. I would start by reading this guide to implementing 2D platformers. As you will see, you have a lot of decisions to make. You have to decide what "type" of platformer you want to make (as described in the guide), you need to come up with characters, you need to decide on the details of the gameplay (how fast will the player's character move, how quickly will it accelerate, how high will it jump, will it be able to have some control of the movement while it's in the air, etc.).

You should break down the task of building the 2D platformer into smaller steps. Here's one possible plan:
* Put a blue rectangle on top of a floor and allow the user to move it around using the arrow keys.
* Make a scrolling background, which you can control with the left and right arrow.
* Improve the scrolling background to have multiple layers at different distances, with transparency.
* Add some platforms to the scrolling demo.
* Get your blue rectangle to be able to jump onto the platforms.
* Play around with the camera.
* Add some enemies (red rectangles are fine).
* Implement collision detection and response.
* Replace the colored rectangles with animated characters.
* Add music and game noises.
* Think of a format to describe a level in and write code to read that format. You might be able to find a format for which other people have written editors. If not, you may have to roll your own, although you can start by writing the files "by hand" to get started.
* ...

These steps are challenges that should be fairly manageable. If you have no idea how to approach them, perhaps you need to learn a bit more programming before you can tackle your 2D platformer.

Good luck!

Share this post


Link to post
Share on other sites
foxcode    299

The sfml main website has pretty good documentation and even example code you can copy and compile to see how it works. http://www.sfml-dev.org/tutorials/2.1/

 

I will address 2D collision briefly but it is covered pretty well on gamedev along with everything else you could want to know about making a 2D game

 

The type of 2D collision you need depends on the style of your platformer, one of the easiest is a tile based world, like the original Mario.

 

To check collision between 2 tiles or rectangles for example, a rectangle that is the ground and another that is the player, you can do something like this. This is code I have wrote just now as a guide, it only handles collision detection, it does not do anything based on that aka collision handling. 

struct Rect
{
  float x; //Position, top left corner x pos
  float y; //Position, top left corner y pos
  float w; //Width of rectangle
  float h; //Height of rectangle
};

static bool CheckCollision(Rect _one, Rect _two)
{
  //Check if rectangles overlap on x axis
  if(_one.x + _one.w < _two.x || //Check if rect one is to the left
     _one.x > _two.x + _two.w    //Check if rect one is to the right
  {
    return false; //No overlap on this axis, collision not possible
  }

  //Check if rectangles overlap on y axis
  if(_one.y + _one.h < _two.y || //Check if rect one is above
     _one.y > _two.y + _two.h    //Check if rect one is below
  {
    return false; //No overlap on this axis, collision not possible
  }

  return true; //Both axis have overlap, collision must have occurred

  
}

Hope this helps, gl

Share this post


Link to post
Share on other sites
BeerNutts    4400

My Old Blog (in my signature) details making an SFML game using a 2d physics library to handle all movement and collision detection/responses.  You can take a look at it for some ideas.

Share this post


Link to post
Share on other sites
Shenzo    107

Oh thank's everyone for the help ! smile.png

Btw , i didn't understand this part sir.Alvaro
 

* Improve the scrolling background to have multiple layers at different distances, with transparency.

 

Edited by Shenzo

Share this post


Link to post
Share on other sites
Satharis    2444

Keep in mind a game is a sum of its parts and each tends to be its own field of experience you need to learn. Part of that is the main reason people say to start with something like a very simple Pong clone and then move to more advanced games, you get a basic game working and then you start layering on more complex things. Even making a GUI of any distinction will take quite a lot of reading and practice to really understand.

 

There isn't really any books or tutorials out there on making an entire game, at the very least they usually just describe ways to create certain parts of the game, which you should take advantage of.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this