2D Toolkit Forum

2D Toolkit => Support => Topic started by: aphexyuri on January 28, 2012, 01:31:43 am

Title: tk2dButton removes tk2dSprite
Post 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
Title: Re: tk2dButton removes tk2dSprite
Post by: unikronsoftware on January 28, 2012, 11:35:56 pm
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?
Title: Re: tk2dButton removes tk2dSprite
Post by: aphexyuri on January 31, 2012, 11:51:34 pm
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
Title: Re: tk2dButton removes tk2dSprite
Post by: aphexyuri on January 31, 2012, 11:53:08 pm
Btw...you'll see that to force the Sprite to show a certain spite, I set the spriteId in the Update method.
Title: Re: tk2dButton removes tk2dSprite
Post by: unikronsoftware on February 01, 2012, 12:43:30 am
To set them dynamically, simply create a setter like this:

Code: [Select]
void SetButtonDownSprite(string name)
{
buttonDownSpriteId = sprite.GetSpriteIdByName(name);
}

That should update the internal values and should work properly.


Hope that helps.
Title: Re: tk2dButton removes tk2dSprite
Post by: aphexyuri on February 03, 2012, 05:40:15 pm
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!