Jump to content

  • Log In with Google      Sign In   
  • Create Account

Looking to get into sprite-based 2D game programming

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Jeffy   Members   -  Reputation: 114


Posted 05 April 2013 - 01:34 PM



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:





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







#2 jms bc   Members   -  Reputation: 448


Posted 05 April 2013 - 02:09 PM

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.

#3 KnolanCross   Members   -  Reputation: 1841


Posted 05 April 2013 - 02:22 PM

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).

#4 PragmaOnce   Members   -  Reputation: 755


Posted 05 April 2013 - 03:28 PM

We'll a few good 2D libraries are:


- Allegro 




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.

#5 Alpheus   Crossbones+   -  Reputation: 6495


Posted 05 April 2013 - 03:45 PM

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.

External Articulation of Concepts Materializes Innate Knowledge of One's Craft and Science
Beginner in Game Development? Read here. And read here.
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts smile.png


#6 Ludus   Members   -  Reputation: 1017


Posted 05 April 2013 - 03:46 PM

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





Edited by Ludus, 05 April 2013 - 03:47 PM.

#7 EddieV223   Members   -  Reputation: 1823


Posted 05 April 2013 - 05:15 PM

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

Edited by EddieV223, 05 April 2013 - 05:23 PM.

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


// C++ Video tutorials



// 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



// SFML 2 book



#8 Racoonacoon   Members   -  Reputation: 443


Posted 05 April 2013 - 07:57 PM

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.

#9 Jeffy   Members   -  Reputation: 114


Posted 07 April 2013 - 05:54 AM

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?

#10 nobodynews   Crossbones+   -  Reputation: 2998


Posted 07 April 2013 - 07:50 AM

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!

#11 Racoonacoon   Members   -  Reputation: 443


Posted 07 April 2013 - 02:25 PM

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.


Given that Fist of Awesome runs on OUYA, iOS, and Android, it's safe to assume that everything is rendered using OpenGL ES. You can't (visually) tell the difference between drawing the individual pixels using something like GDI+ vs drawing textured quads using OGL or DX. They look exactly the same. Either one can be 'purely 2D.' It's just a matter of setting up the states/shaders to get things to look they way you want it. Take the below screenshot from a game a friend and I worked on for example:



Everything is drawn using DirectX 9 (to be more accurate, it uses a wrapper around it called XNA.) Basically you create a bunch of textured squares ( called quads ) send those to the GPU and they pop up on the screen. The projection matrices are set up so that everything is projected into 2D space; there is no 3D.


So, OGL and DX are not 3D specific. They are more like this generic blob that can do whatever you ask them to do (more or less.) You want 2D? Great, build yourself a shader and set up the correct matrices and you got it. 3D? Same story, create your shaders, set you states, read a couple math books and you are good to go.


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.