<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.gideros.rocks/index.php?action=history&amp;feed=atom&amp;title=Tuto_Gideros_Game_Template1_Part_4_Transitions</id>
	<title>Tuto Gideros Game Template1 Part 4 Transitions - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.gideros.rocks/index.php?action=history&amp;feed=atom&amp;title=Tuto_Gideros_Game_Template1_Part_4_Transitions"/>
	<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=Tuto_Gideros_Game_Template1_Part_4_Transitions&amp;action=history"/>
	<updated>2026-11-18T03:04:41Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://wiki.gideros.rocks/index.php?title=Tuto_Gideros_Game_Template1_Part_4_Transitions&amp;diff=23847&amp;oldid=prev</id>
		<title>MoKaLux: Created page with &quot;__TOC__ == Transitions == For our game, we will transition between scenes using a transition scene.  The &#039;&#039;&#039;transitions&#039;&#039;&#039; scene will receive as parameter the next scene to lo...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.gideros.rocks/index.php?title=Tuto_Gideros_Game_Template1_Part_4_Transitions&amp;diff=23847&amp;oldid=prev"/>
		<updated>2024-10-25T19:14:32Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__TOC__ == Transitions == For our game, we will transition between scenes using a transition scene.  The &amp;#039;&amp;#039;&amp;#039;transitions&amp;#039;&amp;#039;&amp;#039; scene will receive as parameter the next scene to lo...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__TOC__&lt;br /&gt;
== Transitions ==&lt;br /&gt;
For our game, we will transition between scenes using a transition scene.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;transitions&amp;#039;&amp;#039;&amp;#039; scene will receive as parameter the next scene to load. The transitions scene will have a MovieClip to simulate transition effects using the &amp;#039;&amp;#039;tweens&amp;#039;&amp;#039; we declared in the &amp;#039;&amp;#039;init.lua&amp;#039;&amp;#039; file.&lt;br /&gt;
&lt;br /&gt;
The transitions can be interrupted by pressing some keys.&lt;br /&gt;
&lt;br /&gt;
Imho it makes sense to create the file in the &amp;#039;&amp;#039;&amp;#039;scenes&amp;#039;&amp;#039;&amp;#039; folder. You can call the file &amp;quot;&amp;#039;&amp;#039;transitions.lua&amp;#039;&amp;#039;&amp;quot;. Here it is:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
Transitions = Core.class(Sprite)&lt;br /&gt;
&lt;br /&gt;
function Transitions:init(xnextscene)&lt;br /&gt;
	self.nextscene = xnextscene&lt;br /&gt;
	-- a movieclip for transitions (you can replace the pixel with a bitmap, ...)&lt;br /&gt;
	local pixel = Pixel.new(g_ui_theme.pixelcolorup, 1, myappwidth, myappheight)&lt;br /&gt;
	local mc = MovieClip.new{{ -- you choose the duration, the effects, ...&lt;br /&gt;
		1, 50, pixel, -- 64, 32&lt;br /&gt;
		{&lt;br /&gt;
			x = { myappleft, myappleft, },&lt;br /&gt;
			y = { 0, myappheight, tweens[31] }, -- tweens[random(#tweens)]&lt;br /&gt;
			alpha = { 1, 0, tweens[19] }, -- tweens[random(#tweens)]&lt;br /&gt;
		}&lt;br /&gt;
	}}&lt;br /&gt;
	mc:play() -- play only once&lt;br /&gt;
	-- order&lt;br /&gt;
	self:addChild(mc)&lt;br /&gt;
	-- listeners&lt;br /&gt;
	mc:addEventListener(Event.COMPLETE, function()&lt;br /&gt;
		self:gotoScene(self.nextscene)&lt;br /&gt;
	end)&lt;br /&gt;
	-- let&amp;#039;s go&lt;br /&gt;
	self:myKeysPressed()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- cancel the transition&lt;br /&gt;
function Transitions:myKeysPressed()&lt;br /&gt;
	self:addEventListener(Event.KEY_DOWN, function(e)&lt;br /&gt;
		if e.keyCode == KeyCode.ESC or e.keyCode == KeyCode.ENTER or e.keyCode == KeyCode.SPACE or e.keyCode == g_keyaction1 then&lt;br /&gt;
			self:gotoScene(self.nextscene)&lt;br /&gt;
		end&lt;br /&gt;
	end)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- scene navigation&lt;br /&gt;
function Transitions:gotoScene(xnextscene)&lt;br /&gt;
	self:removeAllListeners()&lt;br /&gt;
	for i = stage:getNumChildren(), 1, -1 do&lt;br /&gt;
		stage:removeChildAt(i)&lt;br /&gt;
	end collectgarbage()&lt;br /&gt;
	stage:addChild(xnextscene) -- next scene, xnextscene = Class.new()&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Code comments ==&lt;br /&gt;
In the init function we pass the next scene we want to load, eg.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
Transitions.new(Menu.new())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we use a Pixel to cover the whole screen and animate it using a MovieClip. Feel free to make your own transitions.&lt;br /&gt;
&lt;br /&gt;
We can press a key to cancel the transition.&lt;br /&gt;
&lt;br /&gt;
Finally, before switching to the new scene we remove all the current listeners and children to keep the memory consumption low. collectgarbage() helps us with this.&lt;br /&gt;
&lt;br /&gt;
We are ready to load the next scene!&lt;br /&gt;
&lt;br /&gt;
== Next? ==&lt;br /&gt;
Logically the next scene we see is the &amp;#039;&amp;#039;&amp;#039;menu&amp;#039;&amp;#039;&amp;#039; scene?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prev.: [[Tuto Gideros Game Template1 Part 3 Main]]&amp;lt;/br&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Next: [[Tuto Gideros Game Template1 Part 5 Menu]]&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[[Tutorial - Gideros Game Template1]]&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
{{GIDEROS IMPORTANT LINKS}}&lt;/div&gt;</summary>
		<author><name>MoKaLux</name></author>
	</entry>
</feed>