Hardware and OS

Revision as of 12:29, 7 January 2020 by MoKaLux (talk | contribs) (added some content to File execution order)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The Ultimate Guide to Gideros Studio

Hardware and OS

Introduction to hardware system

Getting logical dimensions

Getting device dimensions

Getting system information

Getting and setting orientation

Localization and language

Handling touch and mouse input

Note: The easiest way to detect if the player touches the screen with two fingers, is to control the length of event.allTouches array. If it is 2, then exactly 2 fingers is touching the screen.

local function onTouchesBegin(event)
  local isTwoFinger = (#event.allTouches == 2)




GPS and location


Gideros Studio provides a function for vibration. Consider the following example:


The vibration period is 300 ms for Android. For iOS, device vibrates for a duration which is determined by the operating system.

Disabling screen dimming

Some games may require that player doesn't touch the screen for a long time, e.g. those using accelerometer and gyro to control the actors on the screen. In this case, the screen may dim, depending on the user's activity and device settings. To disable (or enable) screen dimming, use the following commands:

-- disable screen dimming and device sleeping
-- enable screen dimming and device sleeping

Note: this function has no effect on desktop player.


In Gideros runtime, there are 3 kinds of directories: resource, document, and temporary.

Resource directory

Your code, image, audio and all other files are reside at resource directory. Consider the test project below, and examine the 3 directories and corresponding files.

Resource directory.png

The files seen above are stored on a real device and Gideros Player like the following:

{resource directory}/gfx/sprite1.png
{resource directory}/gfx/sprite2.png
{resource directory}/gfx/background.png
{resource directory}/audio/game-music.mp3
{resource directory}/audio/click.wav
{resource directory}/data/list.txt
{resource directory}/main.lua
{resource directory}/game.lua

Resource directory is the default directory. Therefore, to access the files at resource directory, specify the file path as it is:

local sprite1 = Texture.new("gfx/sprite1.png")
local sprite2 = Texture.new("gfx/sprite2.png")
local background = Texture.new("gfx/background.png")
local music = Sound.new("audio/game-music.mp3")
local click = Sound.new("audio/click.wav")

Also, you can use the io library provided by Lua:


You don't need to know the exact path of resource, document, and temporary directories because Gideros Studio provides an easy way to specify files at these directories.

Document directory

You can store a file created by your application in "document" directory. The files created in this directory are permanent among application sessions. For example, you can create and then read files at document directory to save player progress, or keep latest GPS coordinates.

In order to specify a file in document directory, append "|D|" to the beginning of the filename:


Temporary directory

Gideros Studio provides a temporary directory to store files that may not stay permanent between different sessions. Therefore, files created in this directory are not guaranteed to exist when applications runs next time, and may be deleted after application session finishes.
In order to specify a file at temporary directory, append "|T|" to the begining of the file name. Consider the example below:


Note: Optionally, you can access the files at resource directory by adding "|R|" to the beginning of the file name (but you don't need to):

local sprite1 = Texture.new("|R|gfx/sprite1.png")

To sum up, here's a list of file operations on the device:

-- open file.txt at resource directory to read
-- open file.txt at resource directory to read (same as above)
-- open file.txt at documents directory to read
-- open file.txt at temporary directory to read

File execution order

init.lua is the file that is loaded first.

Then we have files in alphabetical order (upper case first, then lowercase), while resolving code dependencies provided.

Finally, main.lua is loaded last.

PREV.: Playing_Sound_and_Music
NEXT: Extend_your_application_with_plugins