/******************************************************************** * EASING Example, Basic usage * * ---------------------------------------------------------------- * * Author : Fabio Falcucci (Allanon) * * License : Freeware * * Version : 1.0 * * Release : - * * Dependancies : Easing.hws * * * * PayPal Support hijoe@tin.it * * Support me on Patreon! https://www.patreon.com/Allanon71 * * Bitcoin https://coindrop.to/allanon * * * * Github repo (leaving) https://github.com/Allanon71 * * Gitea repo (updated) https://gitea.it/allanon/HollywoodLibs * * ---------------------------------------------------------------- * */ ; 1. Include the Easing library @INCLUDE "../../+Includes.hws" @INCLUDE #INC_EASING ; @INCLUDE "Easing.hws" ; 2. Setup a tween for a text string that will cross the screen in 10 seconds ; We need a table to hold the text position Local textPos = { x = 0, y = 320 } ; Let's start the transition tween.start(10000, ; 10 seconds = 10*1000 milliseconds textPos, ; The table where we have our variable we want to smoothly change { x = 600 }, ; One or more targets : in this case we want to reach x=640 in 10 seconds "inoutelastic", ; The name of the easing function we want to use Function() ; A function to call when the transition ends, here we are using an anonymous function to print a message NPrint("Transition Ended! Click Left Mouse Button") WaitLeftMouse() End EndFunction ) ; 3. We need a function we will call regurarly to update and render ; the scene, we also need a variable to store the previous execution ; time so we can calculate the delta time. Local previousTime = 0 Local timer = StartTimer(Nil) Function renderer() ; Calculate the delta time Local currentTime = GetTimer(timer) Local deltaTime = currentTime - previousTime ; Update previousTime variable previousTime = currentTime ; Clear the screen Cls() ; Update the tweens tween.update(deltaTime) ; Render the object TextOut(textPos.x, textPos.y, "HELLO!") EndFunction ; 4. Setup a Interval function to update & render the tweens @ 100FPS ; meaning every 10 milliseconds. Local rendererInterval = SetInterval(Nil, renderer, 10) ; 5. Setup an infinite loop and watch the result Repeat WaitEvent() Forever