For example, every click the "toggle_switch" variable will change from 0 to 1 to 0, but a "click_count" variable could add 1 for every click. The main function of a toggle switch is to switch back and forth between different states, but with additional variables it could also create other effects. By using other mathematical functions it can be toggled in other ways, such as randomly or in reverse sequence. It can go from state 0 to 1 to 2 to 3 and back to 0. Here I used the add feature to make the states sequential. Toggles typically have two states, but it can always have more. This way when you click you can go back and forth between how fast the game is playing. When the switch is 0 the speed is normal, but when the switch is 1 the speed is twice as fast or twice as slow. Toggle switches don't have to be used only for sprites, but can also be used to change the conditions of the game. With a toggle switch in place you can have a character change between two different frames. For example, when you click on the red button it will turn the light on or off.įor each sprite you can have different frames of animation.
This can be used to make actual switches in a game. If you test it out, every time you click it should switch back and forth between the two states. When the "toggle_switch" is 0 the sprite is visible (3) and when it is 1 the sprite is invisible (4). So the variables were set to certain states of the sprite. Now that we can switch the variable between 1 and 0 we want to let the system know what each one means. The second event (2) says, when the " toggle_switch" is greater than 1 it will become 0.
The first event (1) says, on a mouse event left-click the system will add 1 to the " toggle_switch". The first two events are made to switch the variable between 0 and 1. I called the variable " toggle_switch" and made it equal to zero. Right-click on a blank part of the event sheet to find the option in the menu. This is a variable that can be accessed by any part of the event sheet.