Page 1 of 1

2D game with sprites?

Posted: Sun Jul 08, 2018 7:40 pm
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! :)

Re: 2D game with sprites?

Posted: Mon Jul 09, 2018 3:38 pm
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?

Re: 2D game with sprites?

Posted: Wed Jul 11, 2018 6:54 pm
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!

Re: 2D game with sprites?

Posted: Thu Jul 12, 2018 2:30 am
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.

Re: 2D game with sprites?

Posted: Thu Jul 12, 2018 10:17 am
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.

Re: 2D game with sprites?

Posted: Thu Jul 12, 2018 10:42 am
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...)

Re: 2D game with sprites?

Posted: Fri Jul 13, 2018 2:23 am
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!

Re: 2D game with sprites?

Posted: Fri Jul 13, 2018 8:25 am
by devsh
Thats exactly what I would recommend in lieu of the billboard class.

Look at tutorial #3 or #4

Re: 2D game with sprites?

Posted: Sat Jul 14, 2018 5:52 pm
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.

Re: 2D game with sprites?

Posted: Wed Jul 18, 2018 3:02 pm
by funkey

Re: 2D game with sprites?

Posted: Fri Jul 20, 2018 7:56 pm
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.