How do I : Sprite button states [SOLVED]

Get help using Construct 2

Post » Wed May 21, 2014 11:34 pm

Sprite button states:
Im making a WORD SEARCH GAME
I have a sprite that has 2 FRAMES, animation speed 0 (Frame 0 is on, Frame 1 is Off)
As I schedule for Sprite touching the button switch to off, and I touch the button again to switch on?

This sis te CAPX
https://dl.dropboxusercontent.com/u/19024090/Soup.capx

Greetings and Thanks
Last edited by isasaurio on Thu May 22, 2014 2:36 pm, edited 1 time in total.
B
43
S
11
G
2
Posts: 111
Reputation: 3,858

Post » Thu May 22, 2014 4:23 am

Create a global variable that tracks the on/off.

Create an event that changes the variable whenever the button is hit. So for example:

On touch myButton
If myVariable = 0
Set myVariable = 1
else
Set myVariable = 0

Then for the state of the button, set the frame to match your variable.

myButton animationFrame = myVariable
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,603

Post » Thu May 22, 2014 8:34 am

Just change your "activo" variable type to BOOLEAN

Now when you touch your sprite , the boolean "activo" switch between TRUE & FALSE.

If Activo is true : set frame 1

If Activo is false : set frame 0
You do not have the required permissions to view the files attached to this post.
B
13
S
3
G
2
Posts: 49
Reputation: 1,675

Post » Thu May 22, 2014 2:35 pm

vioz wrote:Just change your "activo" variable type to BOOLEAN

Now when you touch your sprite , the boolean "activo" switch between TRUE & FALSE.

If Activo is true : set frame 1

If Activo is false : set frame 0


GREAT works perfect!
Thanks friend.

Greetings from CHILE!
B
43
S
11
G
2
Posts: 111
Reputation: 3,858

Post » Thu May 22, 2014 2:45 pm

You don't need a separate variable at all. You already have two values that hold the state: the frame numbers themselves. Also, you method is inefficient as the frames are set every tick. This method only changes the frame 'on touched'. (Doesn't make much difference yet, but as things get bigger, it's better practice to reduce overhead).
You do not have the required permissions to view the files attached to this post.
ImageImageImage
B
71
S
22
G
248
Posts: 3,761
Reputation: 138,073

Post » Thu May 22, 2014 3:01 pm

blackhornet're right, what I showed has a condition that is not necessary. it is preferable to use the condition of the frame directly.
B
13
S
3
G
2
Posts: 49
Reputation: 1,675

Post » Fri May 23, 2014 12:10 am

Thanks @blackhornet you CAPX run perfect.

There are things that even I can not understand as "ELSES" the "FOR", "FOR EACH" and "booleans"
I need some explanation "FOR DUMMIES".


You are very efficient!!!
B
43
S
11
G
2
Posts: 111
Reputation: 3,858

Post » Fri May 23, 2014 12:26 am

Or this:
You do not have the required permissions to view the files attached to this post.
ImageImageImageImage
B
158
S
66
G
43
Posts: 2,603
Reputation: 35,868


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 28 guests