2D game with sprites?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
sunnystormy
Posts: 105
Joined: Mon Jun 02, 2014 2:32 am
Location: Washington, D.C.
Contact:

2D game with sprites?

Post by sunnystormy »

Howdy!

Been a while since I've posted, but I'm looking into building a game and want to use Irrlicht for a 2D/3D hybrid level design I have in mind. I've looked over the tutorials on the website, but I feel the 2D tutorial is a little terse. I wanted to know if there were some threads here I could look at, or if the greater Irrlicht community could provide some insight, on working with sprites/spritesheets and creating a scene that contains both 2D and 3D elements?

Thank you for your help! :)
My blog: http://fsgdp.wordpress.com "The Free Software Game Development Pipeline"
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: 2D game with sprites?

Post by MartinVee »

I had some success implementing an orthographic camera aligned with the IV quadrant at the top-left corner of the screen. There's a few pitfalls, but I managed to create a whole lot of lot of classes derived from the irrlicht classes to work with 2D elements.

Of course, given the orthographic nature of the camera, 3D objects all seems flat as they don't have any perspective. I didn't have any problem with that, as I wasn't going to have 3D-looking objects in my scenes (I developped those classes to ease the transition between a 2D only engine to Irrlicht, as most developers here only have experience in 2D).

I tried to get my boss to release what I did under an open source licence. He can definitely see the benefits, but so far, I wasn't instructed to do so.

What kind of look are you looking to get? A 2D look with 3D flat-looking effects? Or more like a 3D look with a few 2D elements?
sunnystormy
Posts: 105
Joined: Mon Jun 02, 2014 2:32 am
Location: Washington, D.C.
Contact:

Re: 2D game with sprites?

Post by sunnystormy »

@MartinVee

I was trying to have 2D sprites running across 3D platforms with a camera aligned to the X and Y axis only. I'm wondering if I need to map the sprites as textures onto planes for this to work best?

Again, I'm looking for something that can point me in the right direction.

Thanks!
My blog: http://fsgdp.wordpress.com "The Free Software Game Development Pipeline"
denzelbro
Posts: 50
Joined: Wed Jun 27, 2018 11:53 pm

Re: 2D game with sprites?

Post by denzelbro »

maybe try implementing a top down orthogonal camera with your 2D sprites since this shows depth for your 3D models while maintaining or aligned to a fixed X and Y position.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: 2D game with sprites?

Post by CuteAlien »

Most primitive solution - use IVideoDriver::draw2DImage. You could also use IImage from the GUI which kinda wraps this.
There is IGUISpriteBank which has some support for putting a bunch of sprites together into one spritebank (as seperate textures or as rectangles one one big texture) and has some support to play them as animation.

Those all work - but disadvantage is that you have no support for rotation. And can't do any kind of 3d effects.
To get that you have to map them on planes. And be aware of troubles with z-fighting when you do _not_ use a orthocam (see http://irrlicht.sourceforge.net/forum/v ... =1&t=51598 - and yes, it's still something I want to change, but right now not working on that problem as I'm deep in shader stuff last weeks).

So kinda depends on what exactly you will need.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: 2D game with sprites?

Post by Mel »

My suggestion would be to use polygons and map into them the sprites, then, just rotate, scale and translate the polygon always aligned to the camera, is not hard, and the engine makes the draw calls for you, besides, as you'd be using a 3D background, the integration is easier. Pro-tip, it is posible to enable/disable filtering besides other nice effects the simple 2D drawing doesn't provide on its own. (additive blending, alpha blending, vertex coloring, shaders...)
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
sunnystormy
Posts: 105
Joined: Mon Jun 02, 2014 2:32 am
Location: Washington, D.C.
Contact:

Re: 2D game with sprites?

Post by sunnystormy »

@Mel @CuteAlien

Wow! Thanks for the input! :D

Mel, based on your suggestion, does that mean I'm going to be using the "IMesh" classes to create a custom polygon? I'd appreciate a little more detail there, if you don't mind. :)

Thank you!
My blog: http://fsgdp.wordpress.com "The Free Software Game Development Pipeline"
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: 2D game with sprites?

Post by devsh »

Thats exactly what I would recommend in lieu of the billboard class.

Look at tutorial #3 or #4
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: 2D game with sprites?

Post by Mel »

You could do that indeed, Irrlicht still supports as well the direct rendering of vertex/index lists, so everything can be even more flexible in that matter, but for the sake of future compatibility is better to use meshes, yes.

Meshes are simply a vertex list and an index list. Irrlichts renders lists of triangles, so you have to arrange your vertices and indices in a fashion that create quads. Examples 3 and 4, put you in motion, as has been already suggested.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
funkey
Posts: 4
Joined: Wed Jul 18, 2018 12:57 pm

Re: 2D game with sprites?

Post by funkey »

chronologicaldot
Competition winner
Posts: 688
Joined: Mon Sep 10, 2012 8:51 am

Re: 2D game with sprites?

Post by chronologicaldot »

FYI: You don't actually need to implement IMesh. You need to implement ISceneNode and use the methods IVideoDriver::setMaterial() and IVideoDriver::drawVertexPrimitiveList() to render it.
Personally, I don't like rendering using the 3D mechanisms because it always looks blurry, even without mipmaps. The reason for this is that you need to get the distance perfect to that the image pixels scale 1-to-1 with your screen, which is tricky. Rendering with orthographic view helps, but taste is taste I guess.
Post Reply