2d sprite batch

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
m4rvin
Posts: 32
Joined: Tue May 15, 2007 3:00 am
Contact:

2d sprite batch

Post by m4rvin »

this is my own implementation of a 2d sprite batch. ie draws a whole batch of sprites in one go. quite need for mobile games.

each sprite can do the basic transforms. rotate, scale, color with alpha

it works with IVideoDrivers implementing draw2DVertexPrimitiveList

590 tris @ 40 fps on the android nexus
1144 tris @ 35 fps on the android ( i did the draw cycle 2x )

Image
Image

i used these classes in my first irrlicht game for android. munchy solitaire (munchyapps.com)

i'm sharing back some of my code to this community :)

included are:
> the sprite manager class
> and some systems using the sprite manager
- bitmap font class (uses BmFont from angelcode)
- 2d particle system (ported from love2d.org)

with these classes the game is even a bit playable in the emulator

i hope someone finds them useful. comments and tips like optimization would be appreciated

http://www.munchyapps.com/spriteManager.tar.gz
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

looks nice, but I have no clue how to use this classes !!! :cry:

it's always a good idea to include a small demo that shows how to use it !!!
especially if the code isn't documented (or at least very spartanic documented)...

also, BmFont.cpp claims that "Util.h" can't be found !!! ;)

are there any dependencies beside Irrlicht ??? :shock:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
netpipe
Posts: 669
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Post by netpipe »

its not ment to be complete. its just a rough framework by the looks of it. sorta something to learn from and improve upon.
Live long and phosphor!
-- https://github.com/netpipe/Luna Game Engine Status 95%
m4rvin
Posts: 32
Joined: Tue May 15, 2007 3:00 am
Contact:

Post by m4rvin »

yup, it's not meant to be complete. but it can be plugged in easily.

here's the code with a demo program.

>> i added the path finder class :) --- no demo for that here though

http://www.munchyapps.com/spriteManager.tar.gz

Code: Select all

 
driver->beginScene(true, true, video::SColor(0,0,0,0));

        sprites->clear();

        // add sprite from tile (0,0) size(8,8)
        Sprite *spr = sprites->addSprite(0,0,8,8);
        spr->setPosition(20, 20);
        spr->setScale(4.0f, 4.0f);

       // add more sprites ...
        
        // fonts
        fonts->drawText("the quick brown fox\njumped over\n the lazy dog", 0, 0, w, h, BmFont::ALIGN_CENTER | BmFont::ALIGN_MIDDLE);
        fonts->drawText("the quick brown fox\njumped over\n the lazy dog", 0, 0, w, h, BmFont::ALIGN_RIGHT | BmFont::ALIGN_TOP);
        fonts->drawText("the quick brown fox\njumped over\n the lazy dog", 0, 0, w, h, BmFont::ALIGN_LEFT| BmFont::ALIGN_BOTTOM);

       // each character is actually a sprite
        
        // particles
        float secs = (float)elapsed / 1000.0f;
        ps->update(secs);
        ps->draw(0,0,0,0,0,0,0);
        if (ps->isEmpty())
            ps->start();

        // each particle is a sprite as well

        // draw all the sprites
        sprites->drawAll();

        // you can "sprites->clear()"  ... and draw another set of sprites

driver->endScene();
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

Can we have a binary demo please? :)
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

m4rvin wrote:yup, it's not meant to be complete. but it can be plugged in easily.
I thought so... ;)
m4rvin wrote:here's the code with a demo program.
great, thanks !!! :)
it's always boring when you get a bunch of code without any information on how to use it !!! ;)
so a small demo that shows (at least) the basics is always a goot idea sp one get interested to try it to use !!!
and it's easier to get deeper into the stuff as you have a starting point !!! ;)

well, good work !!!
I like the particle effect (maybe bc it's the only animated thing in the demo :lol: ) !!! :)

if you don't mind, I'll see if I can add it to my IrrExtensions (when I have a bit of sparetime) !!! :?:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply