Animated Sprite Class +example

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

Awesome, thats a great fix...

Ill have a look at it and give any other ideas if need be else it seems good,

Keep it up :)
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Is it v1.4 compatible?
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

I was not downloading 1.4 jet but its build on preaty basic Irrlicht structures/classes which did not change much for long time so I think it is working.

Just try it out and see yourself.
headfonez
Posts: 12
Joined: Wed Oct 31, 2007 2:04 pm

Post by headfonez »

Thanks! (added a "gotoAndStop" function me self :wink: )
doqkhanh
Posts: 158
Joined: Sat Mar 01, 2008 3:14 am
Location: Tokyo, Japan
Contact:

Post by doqkhanh »

Your code in VS 2005 Express Solution, Run perfectly with Irrlicht 1.4

:D a spell miss, sorry
http://www15.brinkster.com/kirikudo/English/sprite.rar

Copy image to debug file after compile :D
doqkhanh
Posts: 158
Joined: Sat Mar 01, 2008 3:14 am
Location: Tokyo, Japan
Contact:

Post by doqkhanh »

Oh no, when I try using this class in my game there wasn't anything on the screen...

May be I was not draw after draw all other 3D and 2D element??

I had been make some change, but with 2 versions (changed and origin one) event in 1-9 picture loaded ok, there was nothing on the screen.

http://code.google.com/p/fosengine/sour ... imSprite.h

Please help me.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Do you mean there is nothing on screen ...that is plain white screen or there is no sprite?

If you draw sprite before you draw anything else (GUI, scene) then your sprite will end at the bottom, possibly covered by other objects.

In that case you should do something like:

Code: Select all

while(device->run())
{
   driver->beginScene(true, true, video::SColor(0,255,255,255));

   smgr->drawAll();
   guienv->drawAll();

   // animate sprites
   sprite1.play();
   sprite2.play();
   ...

   driver->endScene();
}
That will ensure sprites stay always on top. Of course you may choose otherwise.
giuseppegam
Posts: 39
Joined: Thu Jan 11, 2007 2:45 am

Post by giuseppegam »

My error, the drive is not hitting the size spriteSize.Height = spriteSize.Height / divY; the result greater than the image, pq know what? My sprite is only Width.

spriteSize.Width = spriteSize.Width / divX; returns the right size, the error is in Height
giuseppegam
Posts: 39
Joined: Thu Jan 11, 2007 2:45 am

Post by giuseppegam »

The image texture.png works, which are using software to make the images? I Adobe Photoshop?
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

I use Adobe Photoshop or GIMP.
giuseppegam
Posts: 39
Joined: Thu Jan 11, 2007 2:45 am

Post by giuseppegam »

arras wrote:I use Adobe Photoshop or GIMP.
could check, not because the picture is wrong with size, the image texture.png is correct, my image is error.

Code: Select all

#include <irrlicht.h>

using namespace irr;
#include "AnimSprite.h"
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#pragma comment(lib, "Irrlicht.lib")

// objetos globais
IrrlichtDevice* device = 0;
IVideoDriver* driver =0;
ISceneManager* smgr = 0;
IGUIEnvironment* guienv = 0;

int main(int argc, char **argv)
{
// Seta informações da engine    
device = createDevice(EDT_OPENGL, dimension2d<s32>(1024, 768), 24,true, false, false);
device->setWindowCaption(L"Quiz! - 2004-2008 GAM STUDIO");
driver = device->getVideoDriver();
smgr = device->getSceneManager();
guienv = device->getGUIEnvironment();  
IImage* seta =0;
// Inicia o loop para abertura do video
seta = driver->createImageFromFile("seta_esq.png");
ITexture *texture = driver->addTexture("texture", seta);
//driver->makeColorKeyTexture(texture, core::position2d<s32>(0,0));
seta->drop();
AnimSprite sprite1(device, texture ,4,1);
sprite1.addAnimation(0,3,400, true, false);
sprite1.setAnimation(0);
sprite1.setPosition(120,400);

while(device->run())
	{           
        //Coloca a cor de fundo          
		driver->beginScene(true, true, SColor(255,100,101,140));
		//coloca o fundo na tela
		driver->draw2DImage(driver->getTexture("media/fundo.jpg"), core::position2d<s32>(0,0),core::rect<s32>(0,0,1024,768),0, video::SColor(255,255,255,255), true);
		//coloca a seta na tela
		smgr->drawAll();
		sprite1.play();
        driver->endScene();
	} 
return 0;
}
download my image http://rapidshare.com/files/135796710/seta_esq.png.html
giuseppegam
Posts: 39
Joined: Thu Jan 11, 2007 2:45 am

Post by giuseppegam »

Image size 64x64 pixs works, another of the wrong size, my image 100x100, 400x100 total, 4 frames
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Read more about POT (power-of-two) textures, will avoid many problems.
giuseppegam
Posts: 39
Joined: Thu Jan 11, 2007 2:45 am

Post by giuseppegam »

hybrid wrote:Read more about POT (power-of-two) textures, will avoid many problems.

where I read about POT?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, most people today ask google and wikipedia first, I guess they'll know enough for you to get a start.
Post Reply