Texture Animator

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
rtr_18
Posts: 60
Joined: Thu Jun 10, 2010 8:35 am
Location: Programmer

Texture Animator

Post by rtr_18 »

Hi!
I've an array of textures. I need to animate these textures over an image.

Code: Select all

	textureArray.push_back(pManager->getDriver()->getTexture("media/FE/story/scr/ButtonRipple1.png"));
	textureArray.push_back(pManager->getDriver()->getTexture("media/FE/story/scr/ButtonRipple2.png"));
	textureArray.push_back(pManager->getDriver()->getTexture("media/FE/story/scr/ButtonRipple3.png"));
How to do this?
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

Change the UV coordinates of the vertices in the mesh every frame. You can also change the UV coordinates in a vertex shader.
rtr_18
Posts: 60
Joined: Thu Jun 10, 2010 8:35 am
Location: Programmer

Post by rtr_18 »

I've created a Texture animator like this:

Code: Select all

textureAnimator = pManager->getSceneManager()->createTextureAnimator(textureArray,5000,true);
in side the game loop. But nothing happens. Can you post some piece of code?
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

That texture animator just swaps the textures on the given interval. Is that what you're trying to do, or are you trying to move the texture across the mesh?
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

If you put that in your gameloop, then you create a new animator each frame!

Here's an example of an animated billboard.

Code: Select all

array<ITexture*> texarr;

for (int i = 1; i < 10; ++i)
{
  io::path temp = "explosion";
  temp += i;
  temp += ".jpg";
  texarr.push_back(driver->getTexture(temp));
}

ISceneNodeAnimator* tex = smgr->createTextureAnimator(texarr, 50);

scene::IBillboardSceneNode* bill = smgr->addBillboardSceneNode(0, dimension2df(320, 240), vector3df(0,0,0));
bill->setMaterialTexture(0, texarr[0]);
bill->setMaterialFlag(EMF_LIGHTING, 0);
bill->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);

bill->addAnimator(tex);
tex->drop();
Never take advice from someone who likes to give advice, so take my advice and don't take it.
rtr_18
Posts: 60
Joined: Thu Jun 10, 2010 8:35 am
Location: Programmer

Post by rtr_18 »

slavik262 wrote:
Is that what you're trying to do, or are you trying to move the texture across the mesh?
I've to make a blinking image over a blue circle image to indicate that it's the current level. Please see the following link in this forum:

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=40225

Instead of that I'm trying to use a TextureAnimator. Is it possible or not? I've tried what Bate said also. But nothing(none of my images) is visible.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

have you renamed

Code: Select all

for (int i = 1; i < 10; ++i)
{
  io::path temp = "explosion"; /// Your texture name
  temp += i;
  temp += ".jpg"; /// Your texture file extension
  texarr.push_back(driver->getTexture(temp));
} 
Working on game: Marrbles (Currently stopped).
rtr_18
Posts: 60
Joined: Thu Jun 10, 2010 8:35 am
Location: Programmer

Post by rtr_18 »

I've renamed everything to my resource names. Here is my code in side game loop.

Code: Select all

	while(device->run() && driver)
	{
		if (device->isWindowActive())
		{
		 driver->beginScene(true, true, SColor(0,200,200,200)); 

		 env->drawAll();
		 billBoard->addAnimator(textureAnimator);
		 billBoard->setMaterialTexture(0, textureArray[0]); 
		 billBoard->setMaterialFlag(EMF_LIGHTING, 0); 
		 billBoard->setMaterialType(EMT_TRANSPARENT_ADD_COLOR); 
		 billBoard->addAnimator(textureAnimator); 
		 textureAnimator->drop();
		 driver->endScene();
		}
	}
	device->drop();
I've initialised the texture array out side the game loop in main().

Code: Select all

	irr::core::array<irr::video::ITexture*> textureArray;
	textureArray.push_back(driver->getTexture("ButtonRipple1.png"));
	textureArray.push_back(driver->getTexture("ButtonRipple2.png"));
	textureArray.push_back(driver->getTexture("ButtonRipple3.png"));
	irr::scene::ISceneNodeAnimator* textureAnimator = device->getSceneManager()->createTextureAnimator(textureArray,5000,true);
	irr::scene::IBillboardSceneNode* billBoard =  device->getSceneManager()->addBillboardSceneNode(0,dimension2df(320,240),vector3df(10,10,0));
	context.billBoard = billBoard;
	context.textureAnimator = textureAnimator;
Nothing is visible. What to do?
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

This code does not go in your game loop. You are adding a new animator every single frame. Just use

Code: Select all

 billBoard->addAnimator(textureAnimator); 
 billBoard->setMaterialTexture(0, textureArray[0]); 
 billBoard->setMaterialFlag(EMF_LIGHTING, 0); 
 billBoard->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
outside your game loop.
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

rtr_18 wrote:

Code: Select all

	while(device->run())
	{
		if (device->isWindowActive())
		{
		 driver->beginScene(true, true, SColor(0,200,200,200)); 

		 env->drawAll();
		 billBoard->addAnimator(textureAnimator);
		 billBoard->setMaterialTexture(0, textureArray[0]); 
		 billBoard->setMaterialFlag(EMF_LIGHTING, 0); 
		 billBoard->setMaterialType(EMT_TRANSPARENT_ADD_COLOR); 
		 billBoard->addAnimator(textureAnimator); 
		 textureAnimator->drop();
		 driver->endScene();
		}
	}
	device->drop();
You should also think about drawing it! :lol:

Code: Select all

while(device->run() && driver)
{
  driver->beginScene(true, true, SColor(0,200,200,200));
    smgr->drawAll();
    env->drawAll();
  driver->endScene(); 
}
Never take advice from someone who likes to give advice, so take my advice and don't take it.
Post Reply