Hello Guest

Author Topic: tk2dButton removes tk2dSprite  (Read 11882 times)

aphexyuri

  • Newbie
  • *
  • Posts: 14
    • View Profile
tk2dButton removes tk2dSprite
« 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

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dButton removes tk2dSprite
« Reply #1 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?

aphexyuri

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: tk2dButton removes tk2dSprite
« Reply #2 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

aphexyuri

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: tk2dButton removes tk2dSprite
« Reply #3 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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dButton removes tk2dSprite
« Reply #4 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.

aphexyuri

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: tk2dButton removes tk2dSprite
« Reply #5 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!