How do I associate an on touched with a specific instance...

  • Hey All,

    I have looked through the manual and poked about on the forums looking for a solution to what I am hoping is a simple problem. Unfortunately I am not finding a straight-forward answer so I am hoping someone here will lend me a hand.

    I am creating a HUD that has a few instances of a simple square sprite on it. I am aware that each has a UID and that I can assign a instance variable to the spite for use in selecting it later but for some reason I cant figure out how to code the on touched event so that when one particular instance of that sprite is touched/clicked the intended actions will fire.

    if someone could explain how that would work I would be grateful!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • hello

    create an instance variable for your sprite like "instance_name"

    assign a different value for each button "button1", "button2" ...

    make multiple "ontouched" event and in the same event compare the instance variable of the touched sprite so if it's "button1" you make a particular action, if "button2" an other action ...

  • And to be more efficient and elegant, do what Mimiste proposed, but instead of creating multiple "on touched" events, simply create one and put the conditions that test the value of the instance variable as sub events.

  • Worked Like a charm! Thank you both.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)