Parent

Actor

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.

Attributes

behaviors[RW]

(Not documented)

x[RW]

(Not documented)

y[RW]

(Not documented)

stage[RW]

(Not documented)

input_manager[RW]

(Not documented)

resource_manager[RW]

(Not documented)

alive[RW]

(Not documented)

opts[RW]

(Not documented)

sound_manager[RW]

(Not documented)

visible[RW]

(Not documented)

director[RW]

(Not documented)

Public Instance Methods

alive?() click to toggle source

Is the actor still alive?

# File lib/gamebox/actor.rb, line 63
  def alive?
    @alive
  end
hide() click to toggle source

(Not documented)

# File lib/gamebox/actor.rb, line 132
  def hide
    fire :hide_me if visible?
    @visible = false
  end
is(behavior_def) click to toggle source

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
is?(behavior_sym) click to toggle source

Does this actor have this behavior?

# File lib/gamebox/actor.rb, line 76
  def is?(behavior_sym)
    !@behaviors[behavior_sym].nil?
  end
is_no_longer(behavior_sym) click to toggle source

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
play_sound(*args) click to toggle source

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
remove_self() click to toggle source

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
setup() click to toggle source

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
show() click to toggle source

(Not documented)

# File lib/gamebox/actor.rb, line 137
  def show
    fire :show_me unless visible?
    @visible = true
  end
spawn(type, args={}) click to toggle source

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
stop_sound(*args) click to toggle source

Stops a sound via the SoundManager.

# File lib/gamebox/actor.rb, line 122
  def stop_sound(*args)
    @sound_manager.stop_sound *args
  end
update(time) click to toggle source

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
update_behaviors(time) click to toggle source

Calls update on all the actor’s behaviors.

# File lib/gamebox/actor.rb, line 104
  def update_behaviors(time)
    for behavior in @behaviors.values
      behavior.update time
    end
  end
visible?() click to toggle source

(Not documented)

# File lib/gamebox/actor.rb, line 142
  def visible?
    @visible
  end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.