Hello Guest

Author Topic: How do you "hold down" a tk2dButton?  (Read 4992 times)

inkoman

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 13
    • View Profile
How do you "hold down" a tk2dButton?
« on: February 01, 2013, 12:30:56 am »
Say I want to continuously call a function as long as I have a tk2dButton held down - how do I go about this?

sfbaystudios

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: How do you "hold down" a tk2dButton?
« Reply #1 on: February 01, 2013, 12:35:05 am »
If I'm not mistaken, just make sure there's a Collider on the object, and treat it like any other object.  While mouse down, cast a ray, and if the ray is hitting the object (which means clicking or finger on it), update a variable such as "beingTouched = true", and in the update(), " if (beingTouched){ }"

inkoman

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: How do you "hold down" a tk2dButton?
« Reply #2 on: February 01, 2013, 12:52:17 am »
Ah that may be an acceptable solution. I was looking through the documentation and found:

ButtonHandlerDelegate    
ButtonAutoFireEvent: Occurs every frame for as long as the button is held down.

Any idea where and how I would use this delegate?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How do you "hold down" a tk2dButton?
« Reply #3 on: February 01, 2013, 04:39:05 pm »
You have to link up to it from code like so:

Code: [Select]
void Start() {
   tk2dButton button = GetComponent<tk2dButton>(); // or use a drag&dropped variable
   button.ButtonAutoFireEvent += ButtonAutoFire;
}

void ButtonAutoFire(tk2dButton source) {
    Debug.Log("aaaaa!");
}

Its a standard c# event.