Create a file called hud.lua
, require it from game.lua
, and let's start our module.
Our HUD implementation will be based on the idea that we don't want world coordinates to position objects that are not inside the world. Also, we're more used to designing layouts for UIs thinking about (0, 0) on the top-left corner and the Y
axis growing downward.
So that's what we're going to do:
module ( "HUD", package.seeall ) function HUD:initialize () self.viewport = MOAIViewport.new ()
It can be done as follows:
In order to use a different coordinate system, we'll create a new viewport.
viewport:setSize ( SCREEN_RESOLUTION_X, SCREEN_RESOLUTION_Y )
This viewport will have the same size as the screen:
viewport:setScale (SCREEN_RESOLUTION_X, -SCREEN_RESOLUTION_Y )
It won't use world coordinates. Instead, it will use screen coordinates, but we'll invert the
Y
axis so that it grows downward.viewport:setOffset ( -1, 1 )
Now here's something new. The
setOffset
method is used to move the viewport...