Difference between revisions of "SceneManager"
m |
(added some more explanations) |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
<!-- GIDEROSOBJ:SceneManager --> | <!-- GIDEROSOBJ:SceneManager --> | ||
− | ''' | + | '''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform pc.png]][[File:Platform mac.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/> |
− | ''' | + | '''Available since:''' 2020.2<br/> |
− | ''' | + | '''Inherits from:''' [[Special:MyLanguage/Sprite|Sprite]]<br/> |
=== Description === | === Description === | ||
− | An easy way to manage scenes. | + | An easy way to manage scenes. |
− | |||
<source lang="lua"> | <source lang="lua"> | ||
require "scenemanager" | require "scenemanager" | ||
</source> | </source> | ||
+ | '''Note''': works in pair with the [[Easing]] plugin | ||
=== Example === | === Example === | ||
Line 21: | Line 21: | ||
{ | { | ||
["menu"] = Menu, | ["menu"] = Menu, | ||
− | [" | + | ["level01"] = Level01, |
} | } | ||
) | ) | ||
Line 27: | Line 27: | ||
-- from app start to menu | -- from app start to menu | ||
scenemanager:changeScene("menu") | scenemanager:changeScene("menu") | ||
− | -- from menu to | + | -- from menu to level01 |
− | --scenemanager:changeScene(" | + | --scenemanager:changeScene("level01", 1, SceneManager.moveFromRight, easing.outBack) |
+ | </source> | ||
+ | |||
+ | Below you will find what a scene class looks like. | ||
+ | |||
+ | === The Bare Bone of a Scene Class === | ||
+ | <source lang="lua"> | ||
+ | Level01 = Core.class(Sprite) | ||
+ | |||
+ | function Level01:init() | ||
+ | -- BG | ||
+ | application:setBackgroundColor(0x1234AA) | ||
+ | |||
+ | -- LISTENERS | ||
+ | self:addEventListener("enterBegin", self.onTransitionInBegin, self) | ||
+ | self:addEventListener("enterEnd", self.onTransitionInEnd, self) | ||
+ | self:addEventListener("exitBegin", self.onTransitionOutBegin, self) | ||
+ | self:addEventListener("exitEnd", self.onTransitionOutEnd, self) | ||
+ | end | ||
+ | |||
+ | -- GAME LOOP | ||
+ | function Level01:onEnterFrame(e) | ||
+ | end | ||
+ | |||
+ | -- EVENT LISTENERS | ||
+ | function Level01:onTransitionInBegin() | ||
+ | self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self) | ||
+ | end | ||
+ | |||
+ | function Level01:onTransitionInEnd() | ||
+ | self:myKeysPressed() | ||
+ | end | ||
+ | |||
+ | function Level01:onTransitionOutBegin() | ||
+ | self:removeEventListener(Event.ENTER_FRAME, self.onEnterFrame, self) | ||
+ | end | ||
+ | |||
+ | function Level01:onTransitionOutEnd() | ||
+ | end | ||
+ | |||
+ | -- KEYS HANDLER | ||
+ | function Level01:myKeysPressed() | ||
+ | self:addEventListener(Event.KEY_DOWN, function(e) | ||
+ | -- for mobiles and desktops | ||
+ | if e.keyCode == KeyCode.BACK or e.keyCode == KeyCode.ESC then | ||
+ | scenemanager:changeScene("menu", 1, transitions[2], easing.outBack) | ||
+ | end | ||
+ | end) | ||
+ | end | ||
</source> | </source> | ||
{|- | {|- | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
− | === | + | === Methods === |
− | [[Special:MyLanguage/SceneManager.new|SceneManager.new]] '' | + | [[Special:MyLanguage/SceneManager.new|SceneManager.new]] ''creates a new SceneManager object''<br/><!-- GIDEROSMTD:SceneManager.new(table) creates a new SceneManager object --> |
− | [[Special:MyLanguage/SceneManager:changeScene|SceneManager:changeScene]] '' | + | [[Special:MyLanguage/SceneManager:changeScene|SceneManager:changeScene]] ''transitions to a scene''<br/><!-- GIDEROSMTD:SceneManager:changeScene(scene, duration, transition, ease, options) transitions to a scene --> |
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
− | === | + | === Events === |
[[Special:MyLanguage/SceneManager_enterBegin|"enterBegin"]]<br/><!-- GIDEROSEVT:enterBegin--> | [[Special:MyLanguage/SceneManager_enterBegin|"enterBegin"]]<br/><!-- GIDEROSEVT:enterBegin--> | ||
[[Special:MyLanguage/SceneManager_enterEnd|"enterEnd"]]<br/><!-- GIDEROSEVT:enterEnd--> | [[Special:MyLanguage/SceneManager_enterEnd|"enterEnd"]]<br/><!-- GIDEROSEVT:enterEnd--> | ||
[[Special:MyLanguage/SceneManager_exitBegin|"exitBegin"]]<br/><!-- GIDEROSEVT:exitBegin--> | [[Special:MyLanguage/SceneManager_exitBegin|"exitBegin"]]<br/><!-- GIDEROSEVT:exitBegin--> | ||
[[Special:MyLanguage/SceneManager_exitEnd|"exitEnd"]]<br/><!-- GIDEROSEVT:exitEnd--> | [[Special:MyLanguage/SceneManager_exitEnd|"exitEnd"]]<br/><!-- GIDEROSEVT:exitEnd--> | ||
− | === | + | === Constants === |
SceneManager.moveFromRight<br/><!-- GIDEROSCST:SceneManager.moveFromRight--> | SceneManager.moveFromRight<br/><!-- GIDEROSCST:SceneManager.moveFromRight--> | ||
SceneManager.moveFromLeft<br/><!-- GIDEROSCST:SceneManager.moveFromLeft--> | SceneManager.moveFromLeft<br/><!-- GIDEROSCST:SceneManager.moveFromLeft--> |
Revision as of 04:30, 5 November 2020
Supported platforms:
Available since: 2020.2
Inherits from: Sprite
Description
An easy way to manage scenes.
require "scenemanager"
Note: works in pair with the Easing plugin
Example
How to declare and change scenes
require "scenemanager"
require "easing"
scenemanager = SceneManager.new(
{
["menu"] = Menu,
["level01"] = Level01,
}
)
stage:addChild(scenemanager)
-- from app start to menu
scenemanager:changeScene("menu")
-- from menu to level01
--scenemanager:changeScene("level01", 1, SceneManager.moveFromRight, easing.outBack)
Below you will find what a scene class looks like.
The Bare Bone of a Scene Class
Level01 = Core.class(Sprite)
function Level01:init()
-- BG
application:setBackgroundColor(0x1234AA)
-- LISTENERS
self:addEventListener("enterBegin", self.onTransitionInBegin, self)
self:addEventListener("enterEnd", self.onTransitionInEnd, self)
self:addEventListener("exitBegin", self.onTransitionOutBegin, self)
self:addEventListener("exitEnd", self.onTransitionOutEnd, self)
end
-- GAME LOOP
function Level01:onEnterFrame(e)
end
-- EVENT LISTENERS
function Level01:onTransitionInBegin()
self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
end
function Level01:onTransitionInEnd()
self:myKeysPressed()
end
function Level01:onTransitionOutBegin()
self:removeEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
end
function Level01:onTransitionOutEnd()
end
-- KEYS HANDLER
function Level01:myKeysPressed()
self:addEventListener(Event.KEY_DOWN, function(e)
-- for mobiles and desktops
if e.keyCode == KeyCode.BACK or e.keyCode == KeyCode.ESC then
scenemanager:changeScene("menu", 1, transitions[2], easing.outBack)
end
end)
end
MethodsSceneManager.new creates a new SceneManager object SceneManager:changeScene transitions to a scene |
Events"enterBegin" ConstantsSceneManager.moveFromRight |