Class Std::Switch
A switch that can be activated by jumping onto it. This class can either be used to create entirely new switches or attach switch functionality to an already switch sprite.
Usage example (where the sprite with UID 14 is a pow sprite):
Std::Switch.new(UIDS[14]) do puts "Switch activated!" end
Creating a new switch:
Std::Switch.new(x: 200, y: -200) do puts "Switch activated!" end
Class Methods
new()
new(){...} → a_switch
new(sprite){...} → a_switch
new(opts){...} → a_switch
Create a new switch. If no parameters are given, a switch is created at position (0|0).
Parameters
- sprite
-
Use this Sprite instance as the switch. The sprite should have its image set to ground/underground/pow.png.
- opts
-
An option hash with the following keys:
- sprite
Same as the sprite parameter above.
- x
Move the switch to this X position.
- y
Move the switch to this Y position.
- color
-
Color of the switch. Defaults to :blue. Available colors correspond to those listed in the directory ground/underground/switch.
- save
-
This option is false by default. If it is a true value, then this method takes care of storing the switch's state into savegames (by registering an appropriate save_load level event handler). If the switch was activated before saving, it will thus be in an active state when the savegame is loaded again.
If this option is set specifically to the symbol :callback, then in addition to the restoral of the switch state itself, the callback associated with this switch will be run if on loading a savegame it is found that the switch was in an activated state. This is only useful for simple callbacks and allows to circumvent the need for a manually defined save_load handler.
If this option is enabled, the switch must not be created inside a conditional clause. That is, it can only be used if this method is called on the script's toplevel. This restriction comes from the save_load event; see the documentation for the LevelClass class in the core API's documentation for further information.
If not sprite is passed, setting x and y is recommended, this will be used as the creation position for the new sprite.
If a block is given, use that block as the action to execute when the switch gets activated.
Return value
The newly created instance.
Instance Methods
activated?
activated?() → bool
Has the switch already been activated?
on_activate
on_activate() { ... }
Specify the action to execute when the switch is activated.