How do I create a functioning check box?

Just started using Construct 2? Post your questions here

Post » Sun Feb 08, 2015 2:56 am

Hi all - So I am trying to create a check box. Here's what I have so far. An object that is the check box and an object that is a check mark. I want to click on the box and have a check mark spawn so that it gives off the appearance that you "checked" the box. I know how to make it so that when you click on the box the check mark spawns at the origin point. My problem is unchecking the box and then rechecking it and so on and so forth. How do I make it so I can click on the box, have the check mark appear, click on the box again, have the check mark disappear, and then be able to do that back and forth, back and forth. Thanks!
B
5
Posts: 13
Reputation: 261

Post » Sun Feb 08, 2015 4:20 am

Here's a start
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Sun Feb 08, 2015 5:04 am

@codah

Thanks! One question... What allows for the object to toggle back and forth between animation frames like that?
B
5
Posts: 13
Reputation: 261

Post » Sun Feb 08, 2015 5:15 am

The expression 1 - Sprite1.AnimationFrame

If the animation frame is currently 0, then 1 - 0 = 1 and so the frame will change to 1 (checked)
If the animation frame is currently 1, then 1 - 1 = 0 and so the frame will change to 0 (unchecked)

As you saw I made the 2 states as frames in the one sprite rather than 2 sprites, and turned animationspeed to 0 in properties, so they didn't animate between the frames when we didn't want them to.

You can add an instance variable to track state (checked/unchecked) or just continue to use 'Sprite1.AnimationFrame'. If the latter, I suggest you create 2 constant global variables
UNCHECKED = 0
CHECKED = 1
and use those instead of 0 and 1
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Sun Feb 08, 2015 4:45 pm

Thank you very much!
B
5
Posts: 13
Reputation: 261


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests