How do I detect selected (touched) object?

Get help using Construct 2

Post » Mon May 04, 2015 9:30 pm

I have many objects on the layout. When I touch one object, it should be selected (highlighted) to be handled by some control buttons, which I created to rotate and move the selected (touched) object.

My buttons (Rotate - Mirror - Change Color) should apply the action to ONLY a selected object (by touch) on the layout!

Is there a way to detect the selected or touched object?

Any help please?


B
20
S
5
Posts: 10
Reputation: 1,072

Post » Mon May 04, 2015 9:45 pm

Several ways...

Built into the touch and mouse objects are "On-object-touched" or "Is-touching-object" and "On-object-clicked" or you can do a Mouse-button-down&Cursor-over-object condition.

Or you could use an instance variable inside all your objects for IsSelected=0 and change just the selected object to IsSelected=1 when you want it to be controlled and toggle off when out of control... your control events would just need to condition for "IsSelected=1".
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
65
S
17
G
8
Posts: 636
Reputation: 9,333

Post » Mon May 04, 2015 9:58 pm

chrisinfinger wrote:Several ways...

Built into the touch and mouse objects are "On-object-touched" or "Is-touching-object" and "On-object-clicked" or you can do a Mouse-button-down&Cursor-over-object condition.

Or you could use an instance variable inside all your objects for IsSelected=0 and change just the selected object to IsSelected=1 when you want it to be controlled and toggle off when out of control... your control events would just need to condition for "IsSelected=1".


Thank you chrisinfinger,
Ok, in this case the "Control" buttons in the layout will look for an object which has the variable "IsSelected=1" to apply the action on it.

So, the question is: Should all objects be evaluated to know which one has the variable "IsSelected=1"???

Thanks
B
20
S
5
Posts: 10
Reputation: 1,072

Post » Tue May 05, 2015 5:38 am

If you regroup all the possibly moving objects in a family and make the "IsSelected" (make it a boolean variable by the way) a family instance variable.
This way, you check for the instance of the object type member of the family that "IsSelected" and in a single condition you are only picking one instance of one object type.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
284
S
109
G
91
Posts: 7,319
Reputation: 87,487

Post » Tue May 05, 2015 7:08 am

Kyatric wrote:If you regroup all the possibly moving objects in a family and make the "IsSelected" (make it a boolean variable by the way) a family instance variable.
This way, you check for the instance of the object type member of the family that "IsSelected" and in a single condition you are only picking one instance of one object type.


Thank you so much, Kyatric!
B
20
S
5
Posts: 10
Reputation: 1,072


Return to How do I....?

Who is online

Users browsing this forum: Malhog, plinkie, R0J0hound, Syazanie Amirin and 8 guests