Difference between revisions of "SceneManager:changeScene"
From GiderosMobile
(Created page with "'''Available since:''' Gideros 2020.2<br/> '''Class:''' SceneManager<br/> === Description === Transitions between two scenes. <source lang="lua"> SceneManager:changeScene...") |
|||
(6 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
=== Description === | === Description === | ||
Transitions between two scenes. | Transitions between two scenes. | ||
− | < | + | <syntaxhighlight lang="lua"> |
− | SceneManager:changeScene(scene, duration, transition, easing) | + | SceneManager:changeScene(scene,duration,transition,easing) |
− | </ | + | </syntaxhighlight> |
=== Values === | === Values === | ||
− | '''scene''' ( | + | '''scene''' (string) the name of the scene to transition to<br/> |
− | '''duration''' (number) transition duration<br/> | + | '''duration''' (number) transition duration in seconds<br/> |
'''transition''' (constant) transition type<br/> | '''transition''' (constant) transition type<br/> | ||
'''easing''' (constant) easing type<br/> | '''easing''' (constant) easing type<br/> | ||
− | === | + | === Examples === |
− | < | + | '''Simple example''' |
+ | <syntaxhighlight lang="lua"> | ||
scenemanager:changeScene("level1", 2, SceneManager.moveFromRight, easing.outBack) | scenemanager:changeScene("level1", 2, SceneManager.moveFromRight, easing.outBack) | ||
− | </ | + | </syntaxhighlight> |
+ | |||
+ | '''Change scene with a string extra parameter''' | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | -- initialise scene manager | ||
+ | local sceneManager = SceneManager.new { | ||
+ | ['blankscene'] = BlankScene, | ||
+ | ['cutscenescene'] = CutsceneScene, | ||
+ | } | ||
+ | stage:addChild(sceneManager) | ||
+ | |||
+ | local somevalue = "some value" | ||
+ | |||
+ | sceneManager:changeScene('blankscene') | ||
+ | sceneManager:changeScene('cutscenescene', 1, SceneManager.fade, easing.linear, { userData=somevalue }) | ||
+ | |||
+ | -- then in cutscenescene class | ||
+ | CutsceneScene = Core.class(Sprite) | ||
+ | |||
+ | function CutsceneScene:init(value) | ||
+ | print(value) -- some value | ||
+ | -- ... | ||
+ | end | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | '''Change scene with a table extra parameter''' | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | -- initialise scene manager | ||
+ | local sceneManager = SceneManager.new { | ||
+ | ['blankscene'] = BlankScene, | ||
+ | ['cutscenescene'] = CutsceneScene, | ||
+ | } | ||
+ | stage:addChild(sceneManager) | ||
+ | |||
+ | -- load font | ||
+ | local fontName = 'consolas18' | ||
+ | local fontText = string.format('font/%s.txt', fontName) | ||
+ | local fontImage = string.format('font/%s.png', fontName) | ||
+ | local smallFont = Font.new(fontText, fontImage, true) | ||
+ | |||
+ | -- initialise gamestate | ||
+ | local gamestate = { | ||
+ | cutsceneId = 1, | ||
+ | } | ||
+ | |||
+ | -- begin demo | ||
+ | sceneManager:changeScene('blankscene') | ||
+ | sceneManager:changeScene('cutscenescene', 1, SceneManager.fade, easing.linear, | ||
+ | { | ||
+ | userData = { | ||
+ | sceneManager = sceneManager, | ||
+ | gamestate = gamestate, | ||
+ | font = smallFont, | ||
+ | }, | ||
+ | } | ||
+ | ) | ||
+ | |||
+ | -- then in cutscenescene class | ||
+ | CutsceneScene = Core.class(Sprite) | ||
+ | |||
+ | function CutsceneScene:init(params) | ||
+ | -- copy existing systems and objects | ||
+ | for k,v in pairs(params) do | ||
+ | self[k] = v | ||
+ | end | ||
+ | |||
+ | -- load cutscene | ||
+ | local gamestate = self.gamestate | ||
+ | local cutsceneId = gamestate.cutsceneId | ||
+ | |||
+ | -- initialise name text field | ||
+ | local nameText = TextField.new(self.font, ' ') | ||
+ | -- ... | ||
+ | end | ||
+ | </syntaxhighlight> | ||
{{SceneManager}} | {{SceneManager}} |
Latest revision as of 01:13, 12 December 2023
Available since: Gideros 2020.2
Class: SceneManager
Description
Transitions between two scenes.
SceneManager:changeScene(scene,duration,transition,easing)
Values
scene (string) the name of the scene to transition to
duration (number) transition duration in seconds
transition (constant) transition type
easing (constant) easing type
Examples
Simple example
scenemanager:changeScene("level1", 2, SceneManager.moveFromRight, easing.outBack)
Change scene with a string extra parameter
-- initialise scene manager
local sceneManager = SceneManager.new {
['blankscene'] = BlankScene,
['cutscenescene'] = CutsceneScene,
}
stage:addChild(sceneManager)
local somevalue = "some value"
sceneManager:changeScene('blankscene')
sceneManager:changeScene('cutscenescene', 1, SceneManager.fade, easing.linear, { userData=somevalue })
-- then in cutscenescene class
CutsceneScene = Core.class(Sprite)
function CutsceneScene:init(value)
print(value) -- some value
-- ...
end
Change scene with a table extra parameter
-- initialise scene manager
local sceneManager = SceneManager.new {
['blankscene'] = BlankScene,
['cutscenescene'] = CutsceneScene,
}
stage:addChild(sceneManager)
-- load font
local fontName = 'consolas18'
local fontText = string.format('font/%s.txt', fontName)
local fontImage = string.format('font/%s.png', fontName)
local smallFont = Font.new(fontText, fontImage, true)
-- initialise gamestate
local gamestate = {
cutsceneId = 1,
}
-- begin demo
sceneManager:changeScene('blankscene')
sceneManager:changeScene('cutscenescene', 1, SceneManager.fade, easing.linear,
{
userData = {
sceneManager = sceneManager,
gamestate = gamestate,
font = smallFont,
},
}
)
-- then in cutscenescene class
CutsceneScene = Core.class(Sprite)
function CutsceneScene:init(params)
-- copy existing systems and objects
for k,v in pairs(params) do
self[k] = v
end
-- load cutscene
local gamestate = self.gamestate
local cutsceneId = gamestate.cutsceneId
-- initialise name text field
local nameText = TextField.new(self.font, ' ')
-- ...
end