Tuto Gideros Game Template1 Part 2 Init

From GiderosMobile
Revision as of 18:11, 25 October 2024 by MoKaLux (talk | contribs) (Created page with "__TOC__ == the init.lua file == In the ''init.lua'' file we will initialize some global variables. It is nothing too fancy and mostly uses Gideros standard API. In this file...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

the init.lua file

In the init.lua file we will initialize some global variables.

It is nothing too fancy and mostly uses Gideros standard API.

In this file we will initialize:

  • some additional plugins you may have
  • some global app variables, like the user screen size and the app size (mobile friendly)
  • we also setup our fonts variables here because we may use them in more than one scene
  • we setup a table to hold the overall theme of our app. Mostly UI related like app background and buttons
  • finally we also store all tweens in a table we can refer to in other scenes

All of the above variables may be used in multiple if not all scenes of our game, so imho it makes sense to centralize them all here.

The code:

-- plugins

-- global app variables
screenwidth, screenheight = application:get("screenSize") -- the actual user screen size!
myappleft, myapptop, myappright, myappbot = application:getLogicalBounds()
myappwidth, myappheight = myappright - myappleft, myappbot - myapptop
--print(myappleft, myapptop, myappright, myappbot)
--print(myappwidth, myappheight)
ismyappfullscreen = false

-- global ttf fonts
myttf = TTFont.new("fonts/Cabin-Regular-TTF.ttf", 2.8*8) -- UI
myttf2 = TTFont.new("fonts/Cabin-Regular-TTF.ttf", 1.5*8) -- HUD

-- global ui theme
application:setBackgroundColor(0x46464a)
g_ui_theme = {}
g_ui_theme.pixelcolorup = 0xb29058
g_ui_theme.pixelcolordown = 0xc26966
g_ui_theme.textcolorup = 0xf49c13
g_ui_theme.textcolordown = 0xffb889
g_ui_theme._textcolordisabled = 0x87837f
g_ui_theme.tooltiptextcolor = 0xfaff89
g_ui_theme.exit = 0xf41212
g_ui_theme.tooltipoffsetx = -7*8
g_ui_theme.tooltipoffsety = 1*4

-- tweens table for transitions
tweens = {
	"inBack", -- 1
    "outBack", -- 2
    "inOutBack", -- 3
    "inBounce", -- 4
    "outBounce", -- 5
    "inOutBounce", -- 6
    "inCircular", -- 7
    "outCircular", -- 8
    "inOutCircular", -- 9
    "inCubic", -- 10
    "outCubic", -- 11
    "inOutCubic", -- 12
    "inElastic", -- 13
    "outElastic", -- 14
    "inOutElastic", -- 15
    "inExponential", -- 16
    "outExponential", -- 17
    "inOutExponential", -- 18
    "linear", -- 19
    "inQuadratic", -- 20
    "outQuadratic", -- 21
    "inOutQuadratic", -- 22
    "inQuartic", -- 23
    "outQuartic", -- 24
    "inOutQuartic", -- 25
    "inQuintic", -- 26
    "outQuintic", -- 27
    "inOutQuintic", -- 28
    "inSine", -- 29
    "outSine", -- 30
    "inOutSine", -- 31
}

Next?

That's it! In the next part we will code our main.lua file.


Prev.: Tuto Gideros Game Template1 Part 1 Project Setup
Next: Tuto Gideros Game Template1 Part 3 Main


Tutorial - Gideros Game Template1