animated Texture/HUD/GUI

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
ktyrer496
Posts: 15
Joined: Tue Nov 20, 2007 2:22 pm
Location: Preston, UK

animated Texture/HUD/GUI

Post 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
The idea of war is not to die for your country, but to make the other bastard die for his!
Falcon
Posts: 36
Joined: Sun Jan 13, 2008 9:24 pm
Location: Z_California

Post 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?
-< Dante >
< Industry Senior QA Tester>
< IT Project Manager>
< Independent Programmer>-
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post 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?
Image Image Image
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post 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.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post 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.
Image Image Image
eMgz
Posts: 10
Joined: Sat Sep 29, 2007 2:54 am
Contact:

Post 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
no hard no fun - eMgz
ktyrer496
Posts: 15
Joined: Tue Nov 20, 2007 2:22 pm
Location: Preston, UK

Post 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
The idea of war is not to die for your country, but to make the other bastard die for his!
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post 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
ktyrer496
Posts: 15
Joined: Tue Nov 20, 2007 2:22 pm
Location: Preston, UK

Post 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:
The idea of war is not to die for your country, but to make the other bastard die for his!
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post 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 , :)
ktyrer496
Posts: 15
Joined: Tue Nov 20, 2007 2:22 pm
Location: Preston, UK

Post 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!
The idea of war is not to die for your country, but to make the other bastard die for his!
Post Reply