Top Level Namespace

Defined Under Namespace

Modules: Metro, Tmxed Classes: BrandScene, BrandToTitleScene, Class, CustomEasing, FirstScene, GameScene, Hero, Numeric, TemplateMessage, TitleScene

Constant Summary collapse

Game =

To allow an author an easier time accessing the Game object from within their game. They do not have to use the ‘Metro::Game` an instead use the `Game` constant.

Metro::Game

Instance Method Summary collapse

Instance Method Details

#asset_path(name) ⇒ Object

Note:

Paths that are defined within views use this helper and are assumed to be paths relative within the assets directory of the game. For images, samples, and songs in a model consider using a property.

Note:

Also consider the model classes Image, Animation, Song, and Sample for creating the assets found within the assets folder. Each of those will assist with using the asset_path internally to find the asset.

The asset_path is a helper which will generate a filepath based on the current working directory of the game. This allows for game author’s to specify a path relative within the assets directory of their game.

Examples:

Loading a raw Gosu::Image with an ‘asset_path`


class Player < Metro::Model
  def image
    @image ||= Gosu::Image.new( window, asset_path("player.png"), false )
  end
  def draw
    image.draw_rot(x,y,2,angle)
  end
end

See Also:



36
37
38
# File 'lib/metro/asset_path.rb', line 36

def asset_path(name)
  File.join Dir.pwd, "assets", name
end

#error!(messages, details = {}) ⇒ Object

Display an error message defined within the localization file. A game error displays a error title, message, and actions that can be taken to possibly address this issue.

Parameters:

  • message (String)

    the I18n string found in the locale file.

  • details (Hash) (defaults to: {})

    contains all the possible key-value pairs that might be needed for the localized error messages.



25
26
27
28
29
30
31
32
33
# File 'lib/metro/logging.rb', line 25

def error!(messages, details = {})
  details = { show: true, exit: true }.merge details

  message = TemplateMessage.new messages: messages, details: details,
    website: Game.website, contact: Game.contact

  warn message if details[:show]
  exit 1 if details[:exit]
end

#logObject

Generates a default logger to standard out that can be used within Metro or the game.

Examples:

Outputting information at the debug level


log.debug "The the screen resolution is #{Game.width},#{Game.height}"


9
10
11
12
13
14
15
# File 'lib/metro/logging.rb', line 9

def log
  @log ||= begin
    logger = Logger.new(STDOUT)
    logger.level = Logger::DEBUG
    logger
  end
end

#metro_asset_path(name) ⇒ Object

The metro_asset_path is a helper which will generate a filepath based on the directory of the metro library. This is used to retrieve internal assets which can be used to serve up missing images, animations, samples, or songs or defaults that may come with the metro game library.



47
48
49
# File 'lib/metro/asset_path.rb', line 47

def metro_asset_path(name)
  File.join Metro.asset_dir, name
end