Button With Sprite?

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
trollger
Posts: 84
Joined: Tue Jun 01, 2010 2:17 am
Location: At my computer

Button With Sprite?

Post by trollger »

Quick question. I am trying to make a button with a differnt texture for differnt button states: Hover, Pressed, Up, etc...

So first I made a sprite bank

Code: Select all

 
IGUISpriteBank *ButtonSprites = guienv->addEmptySpriteBank("ButtonSprite");
 
Then I loaded two textures

Code: Select all

 
ButtonSprites->addTexture(driver->getTexture("../Media/GUI/SpellButtons/Button_Normal_Hover.png"));
ButtonSprites->addTexture(driver->getTexture("../Media/GUI/SpellButtons/Button_Click_Render.png"));
 
Then I tried to set the two textures to differnt button states

Code: Select all

 
Button->setSpriteBank(ButtonSprites);
Button->setSprite(EGBS_BUTTON_MOUSE_OVER ,0);
Button->setSprite(EGBS_BUTTON_DOWN,1);
 
My code all works it compiles just fine, the console reports the textures loading, and I know that the buttons are positioned correctly because I can still click on them, but none of the textures show up. Sorry if this seems like a "solve my problems" thread but I can not find anything in the API to hint at what I am doing wrong.
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: Button With Sprite?

Post by Cube_ »

I dunno, I never figured it out either and thus I used an external library (I use CEGUI, there are a ton of other viable options too)
"this is not the bottleneck you are looking for"
CuteAlien
Admin
Posts: 9933
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Button With Sprite?

Post by CuteAlien »

Use addTextureAsSprite instead. Otherwise you have to manually set positions in the spritebank.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
trollger
Posts: 84
Joined: Tue Jun 01, 2010 2:17 am
Location: At my computer

Re: Button With Sprite?

Post by trollger »

If I use addTextureAsSprite then I can only use one non animated textures, and that won't work. So how do I add the position of the sprites in the sprites bank manually?
CuteAlien
Admin
Posts: 9933
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Button With Sprite?

Post by CuteAlien »

I think you have to directly modify the array with the positions. Sorry that thread is pretty much the only documentation: http://irrlicht.sourceforge.net/forum/v ... =9&t=25742
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
trollger
Posts: 84
Joined: Tue Jun 01, 2010 2:17 am
Location: At my computer

Re: Button With Sprite?

Post by trollger »

Thanks I read through it and got it working, some better docs would be nice though, maybe Ill make a tutorial.
Post Reply