Module: Smalruby3::SpriteMethod::Control
- Included in:
- Smalruby3::Sprite
- Defined in:
- lib/smalruby3/sprite_method/control.rb
Overview
Control category methods
Constant Summary collapse
- STOP_OPTION =
{ all: "all", this_script: "this script", other_scripts: "other scripts in sprite" }
Instance Method Summary collapse
- #create_clone(option) ⇒ Object
- #delete_this_clone ⇒ Object
- #forever(&_block) ⇒ Object
- #repeat(num, &_block) ⇒ Object
- #stop(option) ⇒ Object
- #wait ⇒ Object
Instance Method Details
#create_clone(option) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/smalruby3/sprite_method/control.rb', line 42 def create_clone(option) if option == "_myself_" # 自分自身のコピーをつくる cloned = clone # 自分自身がつくったものや、お願いしたこともコピーする cloned.instance_variable_set("@dxruby_sprite", DXRuby::Sprite.new(0, 0)) cloned.send(:sync_costumes) end cloned.name += rand(1000000).to_s World.instance.add_target(cloned) end |
#delete_this_clone ⇒ Object
54 55 56 |
# File 'lib/smalruby3/sprite_method/control.rb', line 54 def delete_this_clone raise NotImplementedError, "not implemented: delete_this_clone" end |
#forever(&_block) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/smalruby3/sprite_method/control.rb', line 18 def forever(&_block) loop do yield wait end end |
#repeat(num, &_block) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/smalruby3/sprite_method/control.rb', line 11 def repeat(num, &_block) num.times do yield wait end end |
#stop(option) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/smalruby3/sprite_method/control.rb', line 25 def stop(option) case option when STOP_OPTION[:all] raise StopAll when STOP_OPTION[:this_script] raise StopThisScript when STOP_OPTION[:other_scripts] raise StopOtherScripts else raise ArgumentError.new("invalid option: #{option}") end end |