Difference between revisions of "Core.asyncCall"
From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>") |
|||
(5 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
=== Description === | === Description === | ||
− | + | Launches a function on a separate thread as a background task. | |
+ | <syntaxhighlight lang="lua"> | ||
+ | Core.asyncCall(task,parameters) | ||
+ | </syntaxhighlight> | ||
− | Background threads are only executed when main thread is not running. | + | Background threads are only executed when the main thread is not running. |
− | |||
− | |||
− | |||
− | |||
=== Parameters === | === Parameters === | ||
− | '''task''': (function) function to run in background <br/> | + | '''task''': (function) function to run in background<br/> |
'''parameters''': (multiple) multiple parameters to pass to function '''optional'''<br/> | '''parameters''': (multiple) multiple parameters to pass to function '''optional'''<br/> | ||
+ | |||
+ | === Examples === | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | local function scaleTextsAndBtn() | ||
+ | local tempFontScale=1.02 | ||
+ | |||
+ | Core.yield(.2) | ||
+ | txt1_noads:setScale(tempFontScale) | ||
+ | Core.yield(.1) | ||
+ | txt1_noads:setScale(1) | ||
+ | |||
+ | txt2_plusincome:setScale(tempFontScale) | ||
+ | Core.yield(.1) | ||
+ | txt2_plusincome:setScale(1) | ||
+ | |||
+ | Core.yield(.1) | ||
+ | btn_OK:setScale(1.04) | ||
+ | Core.yield(.2) | ||
+ | btn_OK:setScale(1) | ||
+ | end | ||
+ | |||
+ | Core.asyncCall(scaleTextsAndBtn) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | '''asyncCall used in a Class and with parameters''' | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | if self.imgui:button("VALIDATE") then | ||
+ | -- self:gotoScene("levelX") | ||
+ | Core.asyncCall(LevelX.gotoScene, self, "levelX") -- or self.gotoScene, ... | ||
+ | end | ||
+ | ... | ||
+ | |||
+ | -- change scene | ||
+ | function LevelX:gotoScene(xscene) | ||
+ | scenemanager:changeScene( | ||
+ | xscene, 1, | ||
+ | transitions[math.random(1, #transitions)], | ||
+ | easings[math.random(1, #easings)] | ||
+ | ) | ||
+ | end | ||
+ | </syntaxhighlight> | ||
{{Core}} | {{Core}} |
Latest revision as of 15:26, 13 July 2023
Available since: Gideros 2016.06
Class: Core
Description
Launches a function on a separate thread as a background task.
Core.asyncCall(task,parameters)
Background threads are only executed when the main thread is not running.
Parameters
task: (function) function to run in background
parameters: (multiple) multiple parameters to pass to function optional
Examples
local function scaleTextsAndBtn()
local tempFontScale=1.02
Core.yield(.2)
txt1_noads:setScale(tempFontScale)
Core.yield(.1)
txt1_noads:setScale(1)
txt2_plusincome:setScale(tempFontScale)
Core.yield(.1)
txt2_plusincome:setScale(1)
Core.yield(.1)
btn_OK:setScale(1.04)
Core.yield(.2)
btn_OK:setScale(1)
end
Core.asyncCall(scaleTextsAndBtn)
asyncCall used in a Class and with parameters
if self.imgui:button("VALIDATE") then
-- self:gotoScene("levelX")
Core.asyncCall(LevelX.gotoScene, self, "levelX") -- or self.gotoScene, ...
end
...
-- change scene
function LevelX:gotoScene(xscene)
scenemanager:changeScene(
xscene, 1,
transitions[math.random(1, #transitions)],
easings[math.random(1, #easings)]
)
end