KBTween/README.md

91 lines
3 KiB
Markdown
Raw Normal View History

2022-08-08 16:18:05 +00:00
# KBTweenLib
2022-08-08 16:50:54 +00:00
A tween library for Kaboom that allows easy usage of tweens. It also comes with a package for eases, so you can use it with Kaboom's `lerp()` function if you really wanted.
## Dependencies
### `tween.js`
- **Requires** Kaboom v2000 or later
- **Requires** a JavaScript version that supports ES6 functionality
- **Recommends** Visual Studio Code
- **Recommends** VS Code Intellisense for JSDocs
### `easingpackage.js`
- **Requires** a JavaScript version that supports ES6 functionality
- **Can be used with** Kaboom, any version
## Documentation
`tween()` - Creates a tween to animate properties of an object.
- `0` - `object: string` - The object with the properties being animated.
- `1` - `prop[]: string` - The properties that will be animated.
- `2` - `time: Object` - The properties that define how to animate the object.
- `.from: number` - The initial value to animate from.
- `.to: number` - The new value to animate to.
- *`.time?: number` - The time it takes to animate the object.*
- `.type: number`- Defines how the animation works.
- `3` - *`config?: Object` - The properties that define how to style the animation.*
- *`.ease?: Function` - The ease and smoothness of the animation.*
- *`.onStart?: Function()` - What to run when the tween starts.*
- *`.onUpdate?: onUpdate()` - What to run every time the tween updates.*
- *`.onFinish?: onFinish()` - What to run when the tween ends.*
2022-08-09 17:12:07 +00:00
- `return` - `: Function()` - End the tween manually.
- *`0` - `clean?: bool` - Whether the tween should end where it is (true) or end at `time.to` (false).*
2022-08-08 16:50:54 +00:00
`onFinish` - What to run when the tween ends.
- `0` - `time: Object` - The properties that defined how to animate this object.
- `1` - `config: Object` - The properties that defined how to style this animation.
- `2` - *`loops?: number` - How many times the tween has looped.*
`onUpdate` - What to run every time the tween updates.
- `0` - `frame: number`
- `1` - `second: number`
- `2` - `percent: number`
- `3` - `easePercent: number`
- `4` - `value: number`
`tweentypes`
- `.NORMAL: number`
- `.FOREVER: number`
- `.CONTINUE: number`
- `.PINGPONG: number`
- private `__NOOP: Function`
## Example
```js
2022-08-08 17:07:39 +00:00
import { KBTween } from ".../tween.js";
import { easings } from ".../easingpackage.js";
2022-08-08 16:50:54 +00:00
2022-08-08 17:07:39 +00:00
var k = kaboom(); // Make Kaboom global but also a variable
2022-08-08 17:10:16 +00:00
var twnlib = KBTween(k); // Create new TweenLib instance, pass in Kaboom
// This fixes Intellisense on VSCode not picking up on how Kaboom imports plugins
// Otherwise, if your IDE is smart enough, you can just pass in the tween lib normally, using KBTween as a plugin
2022-08-08 16:50:54 +00:00
loadBean();
var bean = add([
sprite("bean"),
pos(64, 64),
color(255, 255, 255)
]);
2022-08-08 17:07:39 +00:00
twnlib.tween(bean.pos, [ "x" ], {
from: 0,
to: width() - 64,
time: 3.2,
2022-08-09 03:57:19 +00:00
type: tweentypes.PINGPONG
2022-08-08 16:50:54 +00:00
});
2022-08-08 17:07:39 +00:00
twnlib.tween(bean.pos, [ "y" ], {
from: 0,
to: height() - 64,
time: 2,
2022-08-09 03:57:19 +00:00
type: tweentypes.PINGPONG
2022-08-08 16:50:54 +00:00
});
2022-08-08 17:07:39 +00:00
twnlib.tween(bean.color, [ "g", "r" ], {
2022-08-08 16:50:54 +00:00
from: 255,
to: 0,
time: 0.25,
2022-08-09 03:57:19 +00:00
type: tweentypes.PINGPONG
2022-08-08 16:50:54 +00:00
});
```