Difference between revisions of "Core.yield"
From GiderosMobile
(----) |
|||
(7 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | __NOTOC__ | ||
'''Available since:''' Gideros 2016.06<br/> | '''Available since:''' Gideros 2016.06<br/> | ||
'''Class:''' [[Core]]<br/> | '''Class:''' [[Core]]<br/> | ||
=== Description === | === Description === | ||
− | + | Yields the function running as background task. | |
+ | <syntaxhighlight lang="lua"> | ||
+ | Core.yield(state) | ||
+ | </syntaxhighlight> | ||
− | Core.yield([number of seconds to wait]) | + | Core.yield([number of seconds to wait]) |
− | |||
− | |||
− | + | Core.yield(true) -- yield for a single frame and disable auto yield | |
− | + | ||
− | + | Core.yield(false) -- don't yield now, but reenable autoyield | |
=== Parameters === | === Parameters === | ||
'''state''': (number or boolean) number of seconds to yield or boolean to enable/disable auto yield<br/> | '''state''': (number or boolean) number of seconds to yield or boolean to enable/disable auto yield<br/> | ||
− | ---- | + | === Example === |
− | + | <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() | ||
+ | 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) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | === See also === | ||
+ | '''[[Core.asyncCall]]''' | ||
+ | |||
+ | {{Core}} |
Latest revision as of 09:05, 11 November 2024
Available since: Gideros 2016.06
Class: Core
Description
Yields the function running as background task.
Core.yield(state)
Core.yield([number of seconds to wait])
Core.yield(true) -- yield for a single frame and disable auto yield
Core.yield(false) -- don't yield now, but reenable autoyield
Parameters
state: (number or boolean) number of seconds to yield or boolean to enable/disable auto yield
Example
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)
See also