Hardware and OS
The Ultimate Guide to Gideros Studio
- 1 Hardware and OS
- 2 Introduction to hardware system
- 3 Getting logical dimensions
- 4 Getting device dimensions
- 5 Getting system information
- 6 Getting and setting orientation
- 7 Localization and language
- 8 Handling touch and mouse input
- 9 Multitouch
- 10 Gyroscope
- 11 Accelerometer
- 12 GPS and location
- 13 Vibration
- 14 Disabling screen dimming
- 15 Filesystem
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) end
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 application:setKeepAwake(true) -- enable screen dimming and device sleeping application:setKeepAwake(false)
Note: this function has no effect on desktop player.
In Gideros runtime, there are 3 kinds of directories: resource, document, and temporary.
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.
The files seen above are stored on a real device and Gideros Player like the following:
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.
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:
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 io.read("file.txt") -- open file.txt at resource directory to read (same as above) io.read("|R|file.txt") -- open file.txt at documents directory to read io.read("|D|file.txt") -- open file.txt at temporary directory to read io.read("|T|file.txt")
File execution order