Module: Metro::Draws::ClassMethods

Defined in:
lib/metro/models/draws.rb

Instance Method Summary collapse

Instance Method Details

#draw(actor_name, options = {}) ⇒ Object

Define an actor with the given name and options.

As a convenience the draw method will define ‘getter` and `setter` methods for the specified actor.

Examples:

Defining a title label within a scene


class ExampleScene
  draw :title, text: 'Title Screen',
    model: 'metro::ui::label'
    position: '20,20,0',
    scale: '3,3',
    color: 'rgba(255,255,255,1.0)'

  def show
    puts "Where is my title? #{title.x},#{title.y}"
  end
end


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/metro/models/draws.rb', line 32

def draw(actor_name,options = {})

  view_content_for_actor = view.content[actor_name.to_s]

  actor_data = view_content_for_actor.merge(options)
  actor_data[:name] = actor_name

  scene_actor = ModelFactory.new actor_name, actor_data

  define_method actor_name do
    instance_variable_get("@#{actor_name}")
  end

  define_method "#{actor_name}=" do |value|
    instance_variable_set("@#{actor_name}",value)
  end

  drawings.push scene_actor
end

#drawingsObject Also known as: actors

All of the model factories that have been defined.



77
78
79
# File 'lib/metro/models/draws.rb', line 77

def drawings
  @drawings ||= []
end

#draws(*actor_names) ⇒ Object

Define several actors to be drawn.



64
65
66
67
68
69
70
71
72
# File 'lib/metro/models/draws.rb', line 64

def draws(*actor_names)
  actor_names = actor_names.flatten.compact

  actor_names.each do |actor_name|
    draw actor_name
  end

  drawings
end

#play(song_name, options = {}) ⇒ Object

Define a sound actor with the given anem and options.

See Also:



57
58
59
# File 'lib/metro/models/draws.rb', line 57

def play(song_name,options={})
  draw song_name, options.merge(model: "metro::audio::song")
end