2D Toolkit Forum
2D Toolkit => Support => Topic started by: aphexyuri on January 28, 2012, 01:31:43 am
-
Hi,
I encountered a strange behavior...I have a tk2dSprite with a tk2dButton behavior attached to it. I've debugged and the message destination/function is getting called, but as soon as I click on the sprite, the sprite becomes invisible - it still registers the clicks after that, but it's hidden.
Is there something I'm missing or doing wrong?
Thanks,
Yuri
-
This sounds like the button up sprite is incorrect - could you check if the button reappears when you click down on it again (while being held down). also, at which point does it disappear, is it when as soon as it registers a click?
-
Ha! Yes, that was exactly what it was. If I add the button_up / _down values it show a sprite. The only problem is...I'm assigning my sprite dynamically at runtime, and separate instances of the sprites will have different names/ids.
I'm attaching my icon class...is there perhaps a way to set the up/down properties dynamically?
Thanks,
Yuri
-
Btw...you'll see that to force the Sprite to show a certain spite, I set the spriteId in the Update method.
-
To set them dynamically, simply create a setter like this:
void SetButtonDownSprite(string name)
{
buttonDownSpriteId = sprite.GetSpriteIdByName(name);
}
That should update the internal values and should work properly.
Hope that helps.
-
Well, I can see how that could help...thanks.
My need ended up being a bit more specific, so I ended up writing a custom tk2dButton script and attached that to the tk2dSprite. That worked great, and I have the desired flexibility and control.
Thanks!