Page 1 of 1

animated Texture/HUD/GUI

Posted: Sun Mar 02, 2008 8:44 pm
by ktyrer496
hi,

i am making a game and need the health bar to start flashin red when it gets below a certain level, i know the code to change the texture and to detect the level, but have no idea how to animate the texture, or is it just a case of changing the texture every other second or is there a better method?

any help would be much appreciated

Posted: Sun Mar 02, 2008 8:57 pm
by Falcon
I'm guessing your HUD is 2d, so what I would do here is sprite animation.

That would be explained in this Irrlicht tutorial:
http://irrlicht.sourceforge.net/tut006.html

The time code in the draw loop controls the texture swap.


Anyone else have another method?

Posted: Sun Mar 02, 2008 9:07 pm
by JP
I'd probably just switch the textures of the gui element personally, makes for less code and is a bit simpler, and shouldn't cost any more in performance.

If you preload the textures then you won't have any slowdown while the texture loads on the first time you set the textures.

So you'd do something like this:

During loading:
driver->getTexture("bar texture 1.jpg");
driver->getTexture("bar texture 2.jpg");

That will load both the textures into the texture cache so when you set the texture later, using a call to driver->getTexture(".."); it won't have to load it again.

Or you could keep a pointer to the textures to save a call to getTexture which would have to check through the whole texture cache.

In raw opengl i'd just have a grayscale texture for the bar and then change the colour it's rendered in as required, not sure if there's a way to do that in irrlicht though, do the draw2D functions allow you to specify a colour to colour the texture in?

Posted: Sun Mar 02, 2008 9:23 pm
by MasterGod
JP wrote:In raw opengl i'd just have a grayscale texture for the bar and then change the colour it's rendered in as required, not sure if there's a way to do that in irrlicht though, do the draw2D functions allow you to specify a colour to colour the texture in?
That's exactly my idea for him,
API wrote:virtual void irr::video::IVideoDriver::draw2DImage ( const video::ITexture * texture,
const core::position2d< s32 > & destPos,
const core::rect< s32 > & sourceRect,
const core::rect< s32 > * clipRect = 0,
SColor color = SColor(255, 255, 255, 255),
bool useAlphaChannelOfTexture = false
) [pure virtual]

Draws a 2d image using a color.

(if color is other than Color(255,255,255,255)) and the alpha channel of the texture if wanted.

Parameters:
texture,: Texture to be drawn.
destPos,: Upper left 2d destination position where the image will be drawn.
sourceRect,: Source rectangle in the image.
clipRect,: Pointer to rectangle on the screen where the image is clipped to. This pointer can be NULL. Then the image is not clipped.
color,: Color with which the image is colored. If the color equals Color(255,255,255,255), the color is ignored. Note that the alpha component is used: If alpha is other than 255, the image will be transparent.
useAlphaChannelOfTexture,: If true, the alpha channel of the texture is used to draw the image.

Posted: Sun Mar 02, 2008 9:28 pm
by JP
Sorted, that's be the best option then i guess. Slightly more code than using a gui image but it'll do the job better.

Posted: Mon Mar 03, 2008 6:43 pm
by eMgz
i posted a code snippet here

http://irrlicht.sourceforge.net/phpBB2/ ... highlight=

using color interpolation, take a look :)
maybe you dont need to use texture for the bars, just draw a rectangle and play with the colors inside it, you can set a diferent color for each vertex for example, and to make it flash just change the color each X loops in the main loop or something like this

Posted: Tue Mar 04, 2008 10:24 am
by ktyrer496
cheers for all the sugestions, ive used the changing images bit because we have already got tectures for the health bar so can just go changing it to jus normal solid colours, looks pretty cool though.

thanks again

Posted: Tue Mar 04, 2008 11:42 am
by FuzzYspo0N
If you still looking for animated textures, i can help you a lot with the showing and managing of it, even with mouseover and click events...

Take a look here, and if you want to test it for me i can help you out, :)

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

Posted: Wed Mar 05, 2008 10:41 am
by ktyrer496
im liking the menu! :D

not sure im gonna be using anything like that, well not so far, but cheers for the offer i may still take you up on it at some point :wink:

Posted: Wed Mar 05, 2008 10:45 am
by FuzzYspo0N
Just out of interest, the animation is a sprite. it doesnt have to be a menu. So, for a helth bar, u can simply make an animation(use your imagination) of say, 5 frames, and at 5 health healthbar->setPlaying(true) will give u the effect you desire yes?

Anyway , :)

Posted: Wed Mar 05, 2008 11:47 am
by ktyrer496
yes it does, ive already put code ti just switch between just 2 images, it looks good, and is onyl a matter of a few lines, cheers for the help i may try you method out if i get time!

Posted: Wed Mar 05, 2008 3:35 pm
by FuzzYspo0N
No worries, :)