-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb7ad6f
commit e78ddd4
Showing
3 changed files
with
1,065 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# TweenVs Documentation | ||
________________________________ | ||
|
||
```lua | ||
:from(target, property = nil) | ||
``` | ||
Gets the initial value to tween, `target` can be an entity handle or a numeric value | ||
if `target` is an entity handle then `property` has to be specified, this dictates what entity property to tween | ||
valid properties: | ||
```lua | ||
TweenVS.EntProps | ||
{ | ||
"pos" -- entity position | ||
"ang" -- entity angles | ||
} | ||
``` | ||
________________________________ | ||
|
||
```lua | ||
:to(value, duration = 1) | ||
``` | ||
Sets the end value of the tween. | ||
`value` will set the value the tween will interpolate to, this has to match the value type used in `:from()` | ||
`duration` will set the time in seconds in which the tween will go from the initial value to the end value | ||
________________________________ | ||
|
||
```lua | ||
:toLocal(value, duration = 1, localLoop = false) | ||
``` | ||
The same as `:to()` but takes `value` as relative to the entity | ||
`localLoop` will make it so that if the tween is looping, the end value is re-evaluated at the start of each new loop relative to the entity. | ||
________________________________ | ||
|
||
```lua | ||
:start() | ||
``` | ||
Starts the tween. | ||
________________________________ | ||
|
||
```lua | ||
:stop() | ||
``` | ||
Stops the tween, this will stop the tween from being updated in any way. | ||
________________________________ | ||
|
||
```lua | ||
:pause(time = nil) | ||
``` | ||
Pauses the tween, if `time` in seconds is provided this will act as a delay. | ||
________________________________ | ||
|
||
```lua | ||
:unpause() | ||
``` | ||
Unpauses the tween. | ||
________________________________ | ||
|
||
```lua | ||
:loop(loopCount = nil) | ||
``` | ||
Loops the tween, the tween will `start()` itself after it finishes tweening | ||
if `loopCount = -1` the tween will loop forever | ||
________________________________ | ||
|
||
```lua | ||
:bounce(val = true) | ||
``` | ||
If `val` is set to true it will make the tween go backwards, from the end value to the initial value, on each loop | ||
if `val` is set to false it will disable bouncing | ||
requires `loop()` to be at least `1` | ||
________________________________ | ||
|
||
```lua | ||
:chain(tween) | ||
``` | ||
Runs the provided tween when the current tween finishes | ||
`tween` needs to be another `Tween()` class | ||
________________________________ | ||
|
||
```lua | ||
:on(type, func) | ||
``` | ||
Will add a callback function `func` to be run based on the `type` | ||
the functions needs to have the form `function(output)` where `output` is the output value of the tween that will be passed to the function | ||
`type` dictates when the callback is ran, valid types are: | ||
```lua | ||
TweenVS.Callbacks | ||
{ | ||
"update" -- runs the callback function each time the tween updates | ||
"finish" -- runs the callback function when the tween finishes | ||
"start" -- runs the callback function only on the first start of the tween | ||
"everyStart" -- runs the callback function on every other subsequent start, ex: when the tween is looping | ||
"stop" -- runs the callback function when the tween stops | ||
} | ||
``` | ||
________________________________ | ||
|
||
```lua | ||
:easing(easingFunction = nil) | ||
``` | ||
Sets the easing type of the interpolation, the library includes an extensive collection of easing functions, see: `TweenVS.EasingFunctions` | ||
you can also define a custom easing function of the form `function(t)` that returns `t` | ||
________________________________ | ||
|
||
```lua | ||
:invert(val = true) | ||
``` | ||
if `val` is set to `true` it will invert the tween, however it does this by inverting the `t` progress value itself not the start and end values | ||
if `val` is set to `false` it will disable the inversion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,90 @@ | ||
# TweenVS | ||
VScript Tweening library for the Source2 game engine | ||
A simple VScript library for tweening and animating entities and variables. | ||
|
||
## Usage | ||
Place the `TweenVS.lua` file in your `vscripts` folder and require it at the beginning of your script like this: | ||
|
||
```lua | ||
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](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. | ||
```lua | ||
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`: | ||
```lua | ||
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 `.to()` instead of using the variable: | ||
```lua | ||
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: | ||
```lua | ||
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: | ||
```lua | ||
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. | ||
```lua | ||
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 "EaseInElastic" easing functio | ||
``` | ||
See [Documentation.md](Documentation.md) for a list of all functions. |
Oops, something went wrong.