Looking to get into sprite-based 2D game programming

Started by
9 comments, last by Shawn Myers 11 years ago

Hi,

Would consider myself an intermediate C++ programmer and I would like to learn some game programming but I do not really know where to start looking. From what I gathered, either OpenGL or Direct X is supposed to be the starting point for 3d programming. That or making use of an engine like Ogre.

But what about 2d games? This following example appears to be 100% 2D:

http://www.ifightbears.co.uk/

Where can I find a good starting point for learning about entirely sprite-based 2D games?

-Jeffy

Advertisement

Maybe you could look at the communities around software commonly used to make 2d games, like GameMaker and Flash. Or focus on a genre dominated by 2D, like platformers or mobile-casual.

The Four Horsemen of Happiness have left.

If I got your question right, you are looking for some 2d SDK and examples, correct? If that is the case here are two ones that work with C++:

SDL - http://www.libsdl.org/

orx - http://orx-project.org/

Currently working on a scene editor for ORX (http://orx-project.org), using kivy (http://kivy.org).

We'll a few good 2D libraries are:

- Allegro

- SDL

- SFML

I would personally recommend SFML because it's a very clean modern library that is fully object orientated. The other libraries are very C like.

The only problem you will experience with SFML is that SFML 2 has been released but it does not yet have it's tutorials updated. You can go

with SFML 1.6 but then you'd have to learn the new systax once SFML 2 is fully updated. What you can do however is use the tutorials that

they have on their site concerning SFML 2 and just modify the SFML 1.6 version in the areas where the tutorials have not yet been covered.

Good luck.

As far as what direction to go, I would suggest: this article and this article.

As far as libraries and tutorials, I would suggest Lazy Foo's SDL or Seraph's SFML tutorials for starters.

Beginner in Game Development?  Read here. And read here.

 

If you decide to go with SDL, here are a couple resources for tutorials:

http://www.lazyfoo.net/SDL_tutorials/

http://www.sdltutorials.com/

SFML is what you want, of the top 2d libs it's the only one that is OOP. Check my sig.

If this post or signature was helpful and/or constructive please give rep.

// C++ Video tutorials

http://www.youtube.com/watch?v=Wo60USYV9Ik

// Easy to learn 2D Game Library c++

SFML2.2 Download http://www.sfml-dev.org/download.php

SFML2.2 Tutorials http://www.sfml-dev.org/tutorials/2.2/

// Excellent 2d physics library Box2D

http://box2d.org/about/

// SFML 2 book

http://www.amazon.com/gp/product/1849696845/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1849696845&linkCode=as2&tag=gamer2creator-20

Hey Jeffy,

You can use DirectX and OpenGL for 2D games as well. It's just a matter of setting up the right states and shaders to get things the way you want them. Most 2D games you see today are using either DirectX or OpenGL in some way to do their rendering. Getting started with either of these APIs is challenging though, simply due to the huge amount of things you have to learn at once before you can do anything useful. I remember when I was first getting started with DirectX 10 that it took me days before I had a simple triangle drawing on the screen.

So, that said, it is probably best to start at some intermediary and work your way up. That a way you can learn as you go and actually have fun instead of being overwhelmed by a bunch of stuff at once. As others have said, you may want to check out SDL or SFML for window creation and sprite drawing to get you started. Even if you are planning on learning the hard-core stuff such as OpenGL or DX I recommend using these libraries to take care of all the boilerplate code such as window creation and texture loading.

You may want to check this out at some point. It is a great tutorial series (or book really) that covers modern OpenGL. It is scary how many old fixed function tuts are still floating about...you want to avoid those, as they will do you disservice in the long run. The great thing about learning graphics programming is that the skills are easily transferable. If you know DirectX you can pick up on OpenGL fairly easily, and vise-versa.

The above is for if you want to do actual programming and learn the underlying concepts behind graphics programming. If you are more interested in creating a game right off the bat you may want to take a look at a 2D Game Engine such as GameMaker by YoYo Games. I've used GameMaker in the past and I found it to be a nice little engine. I've used Torque2D as well, but for some reason or the other I couldn't really get into it. I think I just didn't like the scripting language all that well. I would avoid Unity if you are only interested in 2D at the moment, because it is clunky to use for 2D development.

Thanks for the great replies everyone.

I am going to work through Seraph's tutorial as it appears to be exactly what I was looking for.

Most 2D games you see today are using either DirectX or OpenGL in some way to do their rendering.

How do you spot wether a game is purely 2D or just being 2D while using DX/OGL? I do not know much about the subject, but from what I can tell that bear fighting game I linked appears to be straight 2D without anything 3D-accelerated. Basically trying to see what the limits are to 2D as far as visual FX is concerned.

Also a few things about terminolgy.

DirectX and OpenGL are basically interfaces that allow the programmer to access the GFX card and SFML(and the others mentioned in the topic) are basically the same but without the 3d capabilites?

To be honest, it's almost impossible to know for sure unless you've been told.

If you go way back to some very old 3d games like Doom, they didn't use a 3d api to make 3d games. They used a 2d API (probably drawing directly to the video frame buffer). It manually did what is now built in to graphics cards. There isn't really anything limiting you by using a 2d API except for the speed of your processor and your own knowledge of 3d mathematics.

Going the other way, a programmer can ignore basically all 3d accellerated features of their API to make their 2d game. The programmer would use 'textured quads' to draw 2d sprites. Once that's implmented all the programmer needs to do is say "draw this sprite at this location" to make their 2d game.

All that being said, there are often hints when seeing a 2d game whether it uses a 3d API under the hood. Rotating sprites is a costly process without using a 3d API in some way. So if you see a lot of rotation it's probably using 3d api. If you see things like the view smoothly zooming in and out on the action that's probably using a 3d API. If you see transparency changes (fade in/out) it's probably using a 3d API. But again, that's all possible without a 3d API.

Things are further confused because a 2d API might be implemented using a 3d API. SFML is implemented in OpenGL for example (and uses that 'textured quads' thing). Because it uses OpenGL, rotating and zooming and using transparency in SFML is simple and fast. SDL was not implemented in a 3d api so you can only do rotating and zooming manually or by getting an add-on, that also does it manually. While SDL allows interoperability with OpenGL, It just creates the window and then the programmer switches to using OpenGL functions so it's mainly just to help set things up in that situation.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

This topic is closed to new replies.

Advertisement