Difference between revisions of "Core.asyncCall"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 16: Line 16:
 
=== Examples ===
 
=== Examples ===
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 +
local txt1_noads = TextField.new(nil, "no ads")
 +
local txt2_plusincome = TextField.new(nil, "plus income")
 +
local btn_OK = TextField.new(nil, "OK")
 +
-- position
 +
txt1_noads:setPosition(64, 64*1)
 +
txt2_plusincome:setPosition(64, 64*3)
 +
btn_OK:setPosition(64, 64*5)
 +
-- scale
 +
local FontScale = 4
 +
local tempFontScale = 8
 +
txt1_noads:setScale(FontScale)
 +
txt2_plusincome:setScale(FontScale)
 +
btn_OK:setScale(FontScale)
 +
-- order
 +
stage:addChild(txt1_noads)
 +
stage:addChild(txt2_plusincome)
 +
stage:addChild(btn_OK)
 +
 
local function scaleTextsAndBtn()
 
local function scaleTextsAndBtn()
local tempFontScale=1.02
+
Core.yield(2)
 
 
Core.yield(.2)
 
 
txt1_noads:setScale(tempFontScale)
 
txt1_noads:setScale(tempFontScale)
Core.yield(.1)
+
Core.yield(1)
txt1_noads:setScale(1)
+
txt1_noads:setScale(FontScale)
  
 +
Core.yield(1)
 
txt2_plusincome:setScale(tempFontScale)
 
txt2_plusincome:setScale(tempFontScale)
Core.yield(.1)
+
Core.yield(1)
txt2_plusincome:setScale(1)
+
txt2_plusincome:setScale(FontScale)
  
Core.yield(.1)
+
Core.yield(1)
btn_OK:setScale(1.04)
+
btn_OK:setScale(tempFontScale)
Core.yield(.2)
+
Core.yield(0.5)
btn_OK:setScale(1)
+
btn_OK:setScale(FontScale)
 
end
 
end
 
   
 
   

Revision as of 03:02, 11 November 2024

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 txt1_noads = TextField.new(nil, "no ads")
local txt2_plusincome = TextField.new(nil, "plus income")
local btn_OK = TextField.new(nil, "OK")
-- position
txt1_noads:setPosition(64, 64*1)
txt2_plusincome:setPosition(64, 64*3)
btn_OK:setPosition(64, 64*5)
-- scale
local FontScale = 4
local tempFontScale = 8
txt1_noads:setScale(FontScale)
txt2_plusincome:setScale(FontScale)
btn_OK:setScale(FontScale)
-- order
stage:addChild(txt1_noads)
stage:addChild(txt2_plusincome)
stage:addChild(btn_OK)

local function scaleTextsAndBtn()
	Core.yield(2)
	txt1_noads:setScale(tempFontScale)
	Core.yield(1)
	txt1_noads:setScale(FontScale)

	Core.yield(1)
	txt2_plusincome:setScale(tempFontScale)
	Core.yield(1)
	txt2_plusincome:setScale(FontScale)

	Core.yield(1)
	btn_OK:setScale(tempFontScale)
	Core.yield(0.5)
	btn_OK:setScale(FontScale)
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