Difference between revisions of "ChangeScene (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
Line 3: Line 3:
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By
 
|-
 
|-
| changeScene("s", t, d) || Definition || AFRLme
+
| changeScene("scn", typ, duration) || Definition || AFRLme
 
|}
 
|}
 
+
<hr>
 
This small function allows you to change to another scene, define the scene transition effect & transition time.
 
This small function allows you to change to another scene, define the scene transition effect & transition time.
{| class="toccolours mw-collapsible mw-collapsed ex"
+
{| class="toccolours mw-collapsible mw-collapsed ts"
 
|-
 
|-
 
! Transition Values
 
! Transition Values
 
|-
 
|-
| 0: no transition (immediate).
+
| [0] eFadeNo: no transition (immediate).
 +
|-
 +
| [1] eFadeIn: fade in.
 +
|-
 +
|  [2] eFadeOut: fade out.
 +
|-
 +
| [3] eFadeInAndOut: fade in & out.
 
|-
 
|-
| 1: fade in.
+
| [4] eFadeToNew: fade to new scene (blending).
 
|-
 
|-
| 2: fade out.
+
| [5] eShiftLeft: wipe left.
 
|-
 
|-
| 3: fade in/out.
+
| [6] eShiftRight: wipe right.
 
|-
 
|-
| 4: fade in/out (with alpha blending).
+
| [7] eTunnelEffect: tunnel fade in & out (circle).
 
|-
 
|-
| 5: wipe left.
+
| [8] eFadeShader: requires a shader to be linked via <span class="inlinecode">shaderSetOptions()</span>.
 
|-
 
|-
| 6: wipe right.
+
| [9] eShiftUp: wipe up.
 
|-
 
|-
| 7: fade in/out (circle).
+
| [10] eShiftDown: wipe down.
 
|}
 
|}
 +
<hr>
 +
  
 
== Instructions ==
 
== Instructions ==
 
1. Add the [[#Main_Script|main script]] to the Visionaire Studio Script Editor & set the script as a definition script.<br/>
 
1. Add the [[#Main_Script|main script]] to the Visionaire Studio Script Editor & set the script as a definition script.<br/>
 
2. To change the current scene...
 
2. To change the current scene...
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
 
changeScene("scene_name", 3, 500) -- fade in/out over 500ms
 
changeScene("scene_name", 3, 500) -- fade in/out over 500ms
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
  
 
== Main Script ==
 
== Main Script ==
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
function changeScene(s, t, d, fe, fd)
+
function changeScene(scn, typ, duration, fe, fd)
  fe = game:getInt(VGameFadeEffect); fd = game:getInt(VGameFadeDelay)
+
  fe = game.FadeEffect -- store fade effect
 +
fd = game.FadeDelay -- store fade delay
 
  -- + --
 
  -- + --
  if t < 0 then t = 0 elseif t > 7 then t = 7 end
+
  if typ < 0 then typ = 0 elseif typ > 10 then typ = 10 end -- fallback in case fade effect is less than 0 or more than 10
  game:setValue(VGameFadeEffect, t); game:setValue(VGameFadeDelay, d)
+
  game.FadeEffect = typ -- update fade effect to specified fade effect
 +
game.GameFadeDelay = duration -- update fade duration to specified fade duration
 
  -- + --
 
  -- + --
  game:setValue( VGameCurrentScene, getObject("Scenes[" .. s .. "]") )
+
  game.CurrentScene = Scenes[scn]
 
  -- + --
 
  -- + --
  game:setValue(VGameFadeEffect, fe); game:setValue(VGameFadeDelay, fd)
+
  setDelay(duration, function() -- restore previous scene effects
 +
  game.FadeEffect = fe -- restore fade effect back to stored fade effect
 +
  game.FadeDelay = fd -- restore fade duration back to stored fade duration
 +
end)
 
end
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
  
 
== Syntax Breakdown ==
 
== Syntax Breakdown ==
Line 54: Line 69:
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left;width:80%" | Description
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left;width:80%" | Description
 
|-
 
|-
| "s" || "string" || This should be a "string" value containing the name of the scene you want to change to.
+
| "scn" || "string" || This should be a "string" value containing the name of the scene you want to change to.
 
|-
 
|-
| t || integer || This should be an integer value between 0 & 7, which will determine the transition effect.
+
| typ || integer || This should be an integer value between 0 & 10, which will determine the transition effect.
 
|-
 
|-
| d || integer || This should be an integer value containing the transition time between scenes, in milliseconds. (only affects transitions 1-7)
+
| duration || integer || This should be an integer value containing the transition time between scenes in milliseconds.
|}
+
|}{{toc}}

Revision as of 14:39, 23 August 2022

Name Type By
changeScene("scn", typ, duration) Definition AFRLme

This small function allows you to change to another scene, define the scene transition effect & transition time.

Transition Values
[0] eFadeNo: no transition (immediate).
[1] eFadeIn: fade in.
[2] eFadeOut: fade out.
[3] eFadeInAndOut: fade in & out.
[4] eFadeToNew: fade to new scene (blending).
[5] eShiftLeft: wipe left.
[6] eShiftRight: wipe right.
[7] eTunnelEffect: tunnel fade in & out (circle).
[8] eFadeShader: requires a shader to be linked via shaderSetOptions().
[9] eShiftUp: wipe up.
[10] eShiftDown: wipe down.


Instructions

1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2. To change the current scene...

changeScene("scene_name", 3, 500) -- fade in/out over 500ms


Main Script

function changeScene(scn, typ, duration, fe, fd)
 fe = game.FadeEffect -- store fade effect
 fd = game.FadeDelay -- store fade delay
 -- + --
 if typ < 0 then typ = 0 elseif typ > 10 then typ = 10 end -- fallback in case fade effect is less than 0 or more than 10
 game.FadeEffect = typ -- update fade effect to specified fade effect
 game.GameFadeDelay = duration -- update fade duration to specified fade duration
 -- + --
 game.CurrentScene = Scenes[scn]
 -- + --
 setDelay(duration, function() -- restore previous scene effects
   game.FadeEffect = fe -- restore fade effect back to stored fade effect
   game.FadeDelay = fd -- restore fade duration back to stored fade duration
 end)
end


Syntax Breakdown

Name Type Description
"scn" "string" This should be a "string" value containing the name of the scene you want to change to.
typ integer This should be an integer value between 0 & 10, which will determine the transition effect.
duration integer This should be an integer value containing the transition time between scenes in milliseconds.