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

Get help using Construct 2

Post » Fri Sep 25, 2015 1:46 am

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!
B
11
S
2
Posts: 65
Reputation: 1,396

Post » Fri Sep 25, 2015 8:13 am

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 ...
B
13
S
4
G
4
Posts: 73
Reputation: 3,507

Post » Fri Sep 25, 2015 9:40 am

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.

Image
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
294
S
117
G
96
Posts: 7,313
Reputation: 71,094

Post » Sat Sep 26, 2015 6:37 pm

Worked Like a charm! Thank you both.
B
11
S
2
Posts: 65
Reputation: 1,396


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests