Actor represent a game object. Actors can have behaviors added and removed from them. Such as :physical or :animated. They are created and hooked up to their optional View class in Stage#create_actor.
Is the actor still alive?
# File lib/gamebox/actor.rb, line 63 def alive? @alive end
(Not documented)
# File lib/gamebox/actor.rb, line 132 def hide fire :hide_me if visible? @visible = false end
Adds the given behavior to the actor. Takes a symbol or a Hash.
act.is(:shootable) or act.is(:shootable => {:range=>3})
this will create a new instance of Shootable and pass
:range=>3 to it
Actor#is does try to require 'shootable' but will not throw an error if shootable cannot be required.
# File lib/gamebox/actor.rb, line 85 def is(behavior_def) behavior_sym = behavior_def.is_a?(Hash) ? behavior_def.keys.first : behavior_def behavior_opts = behavior_def.is_a?(Hash) ? behavior_def.values.first : {} begin require behavior_sym.to_s; rescue LoadError # maybe its included somewhere else end klass = Object.const_get Inflector.camelize(behavior_sym) @behaviors[behavior_sym] = klass.new self, behavior_opts end
Does this actor have this behavior?
# File lib/gamebox/actor.rb, line 76 def is?(behavior_sym) !@behaviors[behavior_sym].nil? end
removed the behavior from the actor.
# File lib/gamebox/actor.rb, line 98 def is_no_longer(behavior_sym) behavior = @behaviors.delete behavior_sym behavior.removed if behavior end
Plays a sound via the SoundManager. See SoundManager for details on how to “define” sounds.
# File lib/gamebox/actor.rb, line 117 def play_sound(*args) @sound_manager.play_sound *args end
Tells the actor’s Director that he wants to be removed; and unsubscribes the actor from all input events.
# File lib/gamebox/actor.rb, line 69 def remove_self @alive = false fire :remove_me @input_manager.unsubscribe_all self end
Called at the end of actor/behavior initialization. To be defined by the child class.
# File lib/gamebox/actor.rb, line 59 def setup end
(Not documented)
# File lib/gamebox/actor.rb, line 137 def show fire :show_me unless visible? @visible = true end
Creates a new actor and returns it. (This actor will automatically be added to the Director.
# File lib/gamebox/actor.rb, line 111 def spawn(type, args={}) @stage.create_actor type, args end
Stops a sound via the SoundManager.
# File lib/gamebox/actor.rb, line 122 def stop_sound(*args) @sound_manager.stop_sound *args end
to be defined in child class
# File lib/gamebox/actor.rb, line 127 def update(time) # TODO maybe use a callback list for child classes update_behaviors time end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.