Touch and Instances

Get help using Construct 2

Post » Thu Dec 05, 2013 8:51 am

Hi. Can anyone try to shed some light on the following:
Scenario: Sprite with a number of instances. Sprite has 2 frames. Using the touch control, but running on PC.
The idea is that when the sprite is touched it animates to frame1 (from 0) else reverts back to frame 0.
Problem: The FIRST TIME any of the instances is touched (mouse button) ALL the instances animate to frame 1. Thereafter it works correctly for each instance.

B
9
S
2
G
1
Posts: 8
Reputation: 1,201

Post » Thu Dec 05, 2013 9:18 am

You probably hyavre your events set up the wrong way. Maybe the else event is triggered at the wrong moment, or you don't pick the right instance in that event.

This is just personal preference, but when I want to toggle I always use a variable.

In your case you could use an instance variable, let's call it FrameToggle.

On Sprite touched - Sprite set variable FrameToggle: 1-FrameToggle
-- System compare two values - Sprite.FrameToggle = 1 - Sprite set frame to : 1
-- System compare two values - Sprite.FrameToggle = 0 - Sprite set frame to : 0

where -- is a subevent.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Dec 05, 2013 9:23 am

Thanks LittleStain, will try that. Still the peculiarity of the scenario bothers me. It seems there is never a dull moment in Construct.
B
9
S
2
G
1
Posts: 8
Reputation: 1,201

Post » Thu Dec 05, 2013 10:41 am

I'm still not comming right with this problem. Same situation when I use a "toggle variable". Could you try to simulate this:

Create Sprite with 2 frames (e.g. green & red) and put a number of instances on Layout. Also add the Touch control. Then enter the following events & actions in the Event Sheet:


Event: Touch Is touching Sprite    Action: Sprite Set animation frame to 1
Event: System Else                      Action: Sprite Set animation frame to 0

The first touch changes ALL instances to frame 1 but thereafter only changes the frame of the particular instance being touched/clicked.
B
9
S
2
G
1
Posts: 8
Reputation: 1,201

Post » Thu Dec 05, 2013 10:59 am

so when touch is not touching a sprite you want to set the frame to 0?

the else event is reacting on the is touching, not on the frame.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Dec 05, 2013 11:02 am

replace the is touching with on touch.

add a subevent if frame is 0 - set frame to 1
add a subevent else - set frame to 0

or you could use the toggle event I mentioned before.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Dec 05, 2013 2:56 pm

Hi man, thanks for your inset. I have found the problem: Sprite's Animation speed has to be 0 ! What can I say?
B
9
S
2
G
1
Posts: 8
Reputation: 1,201


Return to How do I....?

Who is online

Users browsing this forum: David181, dop2000, namaewayukidesu and 13 guests