Difference between revisions of "Hardware and OS"

From GiderosMobile
m
(5 intermediate revisions by the same user not shown)
Line 19: Line 19:
 
== Handling touch and mouse input ==
 
== 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.
+
== Multitouch ==
<br/>
+
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.
<br/>
 
 
 
 
<source lang="lua">
 
<source lang="lua">
 
local function onTouchesBegin(event)
 
local function onTouchesBegin(event)
Line 28: Line 26:
 
end
 
end
 
</source>
 
</source>
 
== Multitouch ==
 
  
 
== Gyroscope ==
 
== Gyroscope ==
Line 38: Line 34:
  
 
== Vibration ==
 
== Vibration ==
 
 
Gideros Studio provides a function for vibration. Consider the following example:
 
Gideros Studio provides a function for vibration. Consider the following example:
<br/>
 
<br/>
 
 
 
<source lang="lua">
 
<source lang="lua">
 
application:vibrate()  
 
application:vibrate()  
 
</source>
 
</source>
<br/>
 
  
 
The vibration period is 300 ms for Android. For iOS, device vibrates for a duration which is determined by the operating system.
 
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 ==
 
== 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:
 
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:
<br/>
 
<br/>
 
 
 
<source lang="lua">
 
<source lang="lua">
 
-- disable screen dimming and device sleeping
 
-- disable screen dimming and device sleeping
Line 62: Line 49:
 
application:setKeepAwake(false)
 
application:setKeepAwake(false)
 
</source>
 
</source>
<br/>
 
  
 
'''Note:''' this function has no effect on desktop player.
 
'''Note:''' this function has no effect on desktop player.
 
== Filesystem ==
 
 
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.
 
 
[[File:Resource directory.png]]
 
 
The files seen above are stored on a real device and Gideros Player like the following:
 
<br/>
 
 
{resource directory}/gfx/sprite1.png<br/>
 
{resource directory}/gfx/sprite2.png<br/>
 
{resource directory}/gfx/background.png<br/>
 
{resource directory}/audio/game-music.mp3<br/>
 
{resource directory}/audio/click.wav<br/>
 
{resource directory}/data/list.txt<br/>
 
{resource directory}/main.lua<br/>
 
{resource directory}/game.lua<br/>
 
<br/>
 
 
Resource directory is the default directory. Therefore, to access the files at resource directory, specify the file path as it is:
 
<br/>
 
 
<source lang="lua">
 
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")
 
</source>
 
<br/>
 
 
Also, you can use the io library provided by Lua:
 
<br/>
 
 
<source lang="lua">
 
io.read("data/list.txt")
 
</source>
 
<br/>
 
 
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.
 
<br/>
 
 
In order to specify a file in document directory, append "|D|" to the beginning of the filename:
 
<br/>
 
 
<source lang="lua">
 
io.write("|D|save.txt")
 
</source>
 
 
=== 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.
 
<br/>
 
In order to specify a file at temporary directory, append "|T|" to the begining of the file name. Consider the example below:
 
<br/>
 
 
<source lang="lua">
 
io.write("|T|temp.txt")
 
</source>
 
<br/>
 
 
'''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):
 
<br/>
 
 
<source lang="lua">
 
local sprite1 = Texture.new("|R|gfx/sprite1.png")
 
</source>
 
<br/>
 
 
To sum up, here's a list of file operations on the device:
 
<br/>
 
 
<source lang="lua">
 
-- 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")
 
</source>
 
 
=== File execution order ===
 
  
  
'''PREV.''': [[Playing_Sound_and_Music]]<br/>
+
'''PREV.''': [[Profiling]]<br/>
'''NEXT''': [[Extend_your_application_with_plugins]]
+
'''NEXT''': [[Making a Plugin]]

Revision as of 01:36, 13 August 2020

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

Multitouch

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

Gyroscope

Accelerometer

GPS and location

Vibration

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

application:vibrate()

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.


PREV.: Profiling
NEXT: Making a Plugin