-
Notifications
You must be signed in to change notification settings - Fork 9
Metro Models
Franklin Webber edited this page Nov 25, 2012
·
3 revisions
Metro defines a number of Models.
- position
- scale
- color
- font
- text
- align - 'left', 'center', 'right'
- vertical_align - 'top', 'center', 'bottom'
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
- position
- alpha
- scale
- padding
- options
- unselected_color
- selected_color
- selection_sample
- movement_sample
- enabled
- layout - 'vertical' or 'horizontal'
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
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
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
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).
class BuildScene < GameScene
draw :grid, model: "metro::audio::song",
volume: 0.5,
state: "stop"
end