Difference between revisions of "Sliding Interface MKIII (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
Line 10: Line 10:
 
{| class="ts"
 
{| class="ts"
 
|-
 
|-
| ''Quick note: The interface will only slide in or out if the interface is fully in or out. You can't interrupt it once you start it sliding. The only way to interrupt it & maintain the correct speed would require math calculations to get the current percentage between the start position & target position, which in this case is more hassle than it's worth.''
+
| ''Quick note #1: The interface will only slide in or out if the interface is fully in or out. You can't interrupt it once you start it sliding. The only way to interrupt it & maintain the correct speed would require math calculations to get the current percentage between the start position & target position, which in this case is more hassle than it's worth.''
 +
|
 +
|- ''quick note #2: It's technically possible to slide an interface in or out with a single line of code, using the to() tweening function that I am using in the function examples below. However, we are using the functions so that we have less to type overall & the function can be used for multiple interfaces instead of having to write new code blocks for additional functions - just think of it as a workflow function used to save a bit of time in the long run.
 
|}
 
|}
  
Line 21: Line 23:
 
local tInt = {
 
local tInt = {
  
["int_example"] = { In = {x = 390, y = 710}, Out = {x = 390, y = 530}, duration = 1000, eIn = easeQuintOut, eOut = easeBounceOut }
+
["int_example_1"] = { In = {x = 390, y = 710}, Out = {x = 390, y = 530}, duration = 1000, eIn = easeQuintOut, eOut = easeBounceOut },
 +
["int_example_2"] = { In = {x = 390, y = -190}, Out = {x = 390, y = -10}, duration = 1200, eIn = easeQuintOut, eOut = easeQuintIn }
  
 
}
 
}

Revision as of 23:49, 14 August 2022

Name Type By
Sliding Interface MKIII Definition AFRLme

This script allows you to slide interfaces in/out on mouse over/out, via mouse wheel, via key input, or via an interface button. Visionaire Studio 5+ is required to run this script.


Quick note #1: The interface will only slide in or out if the interface is fully in or out. You can't interrupt it once you start it sliding. The only way to interrupt it & maintain the correct speed would require math calculations to get the current percentage between the start position & target position, which in this case is more hassle than it's worth.

Version One (tables)

This version uses Lua tables/arrays for storing the positional, easing, & duration data for each interface you want to slide out. This version is easier to use overall as you don't need to manually specify all of the data each time into the function.

Instructions

1a. Add this script into the script section of the Visionaire Studio editor & set as a defintion type script...
local tInt = {

["int_example_1"] = { In = {x = 390, y = 710}, Out = {x = 390, y = 530}, duration = 1000, eIn = easeQuintOut, eOut = easeBounceOut },
["int_example_2"] = { In = {x = 390, y = -190}, Out = {x = 390, y = -10}, duration = 1200, eIn = easeQuintOut, eOut = easeQuintIn }

}

function slideInt(int, dir)
  
  if dir and (Interfaces[int].Offset.x == tInt[int].In.x and Interfaces[int].Offset.y == tInt[int].In.y) then -- slide out
    Interfaces[int]:to(tInt[int].duration, { Offset = {x = tInt[int].Out.x, y = tInt[int].Out.y} }, tInt[int].eOut)
  elseif not dir and (Interfaces[int].Offset.x == tInt[int].Out.x and Interfaces[int].Offset.y == tInt[int].Out.y) then -- slide in
    Interfaces[int]:to(tInt[int].duration, { Offset = {x = tInt[int].In.x, y = tInt[int].In.y} }, tInt[int].eIn)
  end
  
end

1b. You need to edit the script above & insert the names of any interfaces you want to be able to slide in & out. You will also need to define the default position of the interfaces [In] & the target position of the interfaces [Out]. Don't forget to include the duration it should take the interface to slide in or out, or the easing you want to use.


Quick note: Visionaire Studio supports most of the easing options listed on this page, however in Visionaire Studio easings are written like this: easeQuintInOut, instead of this: easeInOutQuint.

2a. To use this script you need to create an execute a script action part inside of the key actions, mouse enters/leave actions, command actions, etc. that you want to use to slide an interface out with & then you would insert a line of code that looks like something along the lines of this...

slideInt("int_example", true)

2b. To slide the interface back in you would use the same steps as 2a, except the script would look like something along the lines of this...

slideInt("int_example", false)


Resources

Name Description
sliding_interface_vs4.zip A working example of the script in action. Visionaire Studio 4.0.1+ required to run the included .ved file.