Git Product home page Git Product logo

tweenvs's Introduction

TweenVS

A simple VScript library for tweening and animating entities and variables.

Alt Text

Usage

Place the TweenVS.lua file in your vscripts folder and require it at the beginning of your script like this:

local TweenVS = require 'TweenVS'

Done! Now you can create Tweens using the TweenVS.Tween() class.

This library was mainly written for CS2 but it should work with most Source2 games.

Documentation

See Documentation.md

Examples

TweenVS uses a cascading syntax, this allows you to chain methods to create animation sequences in a readable and concise manner.

You also don't need to worry about updating the tweens, they run on their own clock and start updating as soon as you run the :start() function.

Tweening a variable

This code will take the value of testVar and interpolate to 10 in 2 seconds.

local testVar = 1

TweenVS.Tween()
:from(testVar)  --from the current value of `testVar`
:to(10, 2)      --tween from the value of `testVar` to 10 in 2 seconds
:start()        --start tweening

However this won't do much by itself, as it only takes in the value of testVar as REFERENCE and can't update the variable.
In order to get the tweened value out, you can use the .on() function.
This code will call the testFunc function and pass in the output value of the tween on update:

function testFunc(val)

    print("Tweened value is: " .. tostring(val))    --print out the tweened value
end

local testVar = 1

TweenVS.Tween()
:from(testVar)          --from the current value of `testVar`
:to(10, 2)              --tween from the value of `testVar` to 10
:start()                --start tweening
:on("update", testFunc) --call the `testFunc` function with the output value

The code above can also be written like this, declaring the function in the tween body and putting 1 directly in :from() instead of using the variable:

TweenVS.Tween()
:from(1)
:to(10, 2)
:start()    --start tweening
:on("update", function(val)

    print("Tweened value is: " .. tostring(val))    --print out the tweened value
end)

Tweening an entity property

You can also pass an entity handle instead of a numeric value, accompanied by a property to tween.
This code will make the player's view rotate 180 degrees on the y axis:

local ply = Entities:FindByClassname(nil, "player")

TweenVS.Tween()
:from(ply, "ang")               --from current player angles
:toLocal(QAngle(0, 180, 0), 2)  --rotate 180 degrees on the y-axis local to the entity for 2 seconds
:start()                        --start tweening

While separating functions on new lines is recommended for readibility, you can also write the same setup like this:

local ply = Entities:FindByClassname(nil, "player")

TweenVS.Tween():from(ply, "ang"):toLocal(QAngle(0, 180, 0), 2):start()

Making it complicated.

Modifying the code from above, we can tweak the player's position in complex ways using just a few of the methods provided by the library.

local ply = Entities:FindByClassname(nil, "player")

TweenVS.Tween()
:from(ply, "pos")               --from current player position
:toLocal(Vector(0, 100, 0), 1)  --move 100 units on the local y-axis in 2 seconds
:loop(5)                        --loop 5 times
:bounce()                       --reverse direction on every loop
:pause(1)                       --pause for 1 second before starting
:start()                        --start tweening
:easing(TweenVS.EaseOutBounce); --use the "EaseOutBounce" easing function

See Documentation.md for a list of all functions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.