Skip to content
Franklin Webber edited this page Nov 25, 2012 · 3 revisions

Metro Models

Overview

Metro defines a number of Models.

Example

Defining a metro::ui::label within a scene:

class TitleScene < GameScene

  draw :title, model: "metro::ui::label",
    text: "STARRY KNIGHT",
    position: "200,300,1",
    font: { name: 'Comic Sans', size: 60 },
    color: "rgba(255,255,0,1.0)",
    align: 'center',
    vertical_align: 'center'

end

Example

Defining a metro::ui::menu within a scene:

class TitleScene < GameScene

  draw :menu, model: "metro::ui::menu",
    position: "465,324,5",
    alpha: 255,
    scale: "1.0,1.0",
    padding: 20,
    options: [ "Start Game", "Exit" ]
    unselected_color: "rgba(119,119,119,0.0)",
    selected_color: "rgba(255,255,255,0.0)",
    selected_sample: 'dong.wav',
    movement_sample: 'ding.wav',
    enabled: true,
    layout: 'horizontal'

  def start_game
    puts 'Start Game Selected'
  end

  def exit
    puts 'Exiting Game'
    Kernel.exit
  end
end

Defining a menu with custom actions:

class TitleScene < Metro::Scene

  draw :menu, model: "metro::ui::menu",
    position: "465,324,5",
    alpha: 255,
    scale: "1.0,1.0",
    padding: 20,
    options: { "Start Game" => 'execute_this_method_on_start',
      "Exit" => 'exit_game_for_method' }

  def execute_this_method_on_start
    puts "Starting the Game"
  end

  def exit_game_for_method
    puts "Exiting the Game``"
  end

end

Example

Defining an image within a scene:

class TitleScene < Metro::Scene
  draw :logo, model: "metro::ui::image",
    position: "536,147,4",
    color: "rgba(255,255,255,1.0)",
    image: "player.png",
    angle: 0.0,
    scale: "1.0,1.0"

end

Example

Defining a Rectangle within a scene:

class TitleScene < Metro::Scene
  draw :box, model: "metro::ui::rectangle",
    position: "10,200,4",
    color: "rgba(255,255,255,1.0)",
    dimensions: "300,400"

end

Example

class BuildScene < GameScene
  draw :grid, model: "metro::ui::grid_drawer",
    position: "20,20",
    color: "rgba(255,255,255,0.5)",
    spacing: 20,
    dimensions: "100,100"
end
  • song
  • volume
  • state - 'play', 'stop' (Initially a song will be in the 'play' state. Setting the value to anything else will cause the song not to play at start up).

Example

class BuildScene < GameScene
  draw :grid, model: "metro::audio::song",
    volume: 0.5,
    state: "stop"
end
Clone this wiki locally