npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pixi-tween

v0.2.0

Published

pixi-tween is a plugin for Pixi.js v4.1 or higher to create ...

Downloads

439

Readme

pixi-tween

pixi-tween is a plugin for Pixi.js v3.0.8 or higher to create tween animations.

Online examples: Easing, TweenPath

Installation

npm install pixi-tween

Usage

Browserify - Webpack

If you use Browserify or Webpack you can use pixi-tween like this:

var PIXI = require('pixi.js');
var tweenManager = require('pixi-tween'); //pixi-tween is added automatically to the PIXI namespace

//create PIXI renderer
var renderer = new PIXI.autoDetectRenderer(800,600);
document.body.appendChild(renderer.view);
var stage = new PIXI.Container();

function animate(){
  window.requestAnimationFrame(animate);
  renderer.render(stage);
  PIXI.tweenManager.update();
}
animate();

Prebuilt files

var renderer = new PIXI.autoDetectRenderer(800,600);
document.body.appendChild(renderer.view);
var stage = new PIXI.Container();

function animate(){
  window.requestAnimationFrame(animate);
  renderer.render(stage);
  PIXI.tweenManager.update();
}
animate();

How it works

This plugin add a new namespace names tween to the PIXI namespace, and this new namespace has 3 new classes Tween, TweenPath and TweenManager, also add an Easing object. And create an instance for TweenManager in PIXI.tweenManager, but all you need is add PIXI.tweenManager.update() in your requestAnimationFrame. You can pass as params for PIXI.tweenManager.update(delta) your own delta time, if you don't pass anything it will be calculated internally, for max accuracy calculating the delta time you can use the AnimationLoop plugin.

When a tween is ended, the instance will kept in the memory and in the tweenManager, but you can prevent this if you set .expire = true in the tween.

Using AnimationLoop

var renderer = new PIXI.autoDetectRenderer(800,600);
document.body.appendChild(renderer.view);

var animationLoop = new PIXI.AnimationLoop(renderer);

//Add a postrender or prerender event to add the tweenManager.update in the raf.
animationLoop.on('postrender', function(){
  PIXI.tweenManager.update(this.delta); //Pass as param the delta time to PIXI.tweenManager.update
});

animationLoop.start();

Events

Tween extends from PIXI.utils.EventEmitter, and emit some events: start, end, repeat, update, stop and pingpong. More info: Node.js Events

  • start - callback(): Fired when the tween starts. If the tween has a delay, this event fires when the delay time is ended.
  • end - callback(): Fired when the tween is over. If the .loop option it's true, this event never will be fired, and if the tween has an .repeat number, this event will be fired just when all the repeats are done.
  • repeat - callback(repeat): Fired at every repeat cycle, if your tween has .repeat=5 this events will be fired 5 times.
  • update - callback(elapsedTime): Fired at each frame.
  • stop - callback(): Fired only when it's used the .stop() method. It's useful to know when a timer is cancelled.
  • pingpong - callback(): If the pingPong option it's true, this events will be fired when the tweens returns back.

Paths

Move an object along a path it's easy with TweenPath. TweenPath use a similar PIXI.Graphics API to create paths, and once it's created our path we just need to add it to a tween with .path = ourPathCreated.

If you need draw your path (useful to debug), PIXI.Graphics has been enhanced with a new method named .drawPath(path). Use it the same way like .drawRectanle, .drawShape, etc...

Examples

See the Examples folder.

API

TweenManager

constructor()

The constructor

.tweens

An array with the tweens created

.update( delta )

The update method, make sure it is in the raf. You can pass a fixed delta time (like 0.016), your own calculated delta, or nothing. (Delta time in seconds not milliseconds).

.removeTween( tween )

Remove a tween from the .tweens array in the next frame.

.addTween( tween )

Normally you want to use .createTween(target) to create a tween, but, you can also create a tween with new PIXI.Tween(target) and add it in the manager with this method.

.createTween( target )

Return a new instance of PIXI.Tween managed by this tweenManager.

.getTweensForTarget( target )

Return an array with all the tweens for the given target.

TweenPath

constructor()

The constructor

.moveTo( x, y )

See PIXI.Graphics#moveTo

.lineTo( x, y )

See PIXI.Graphics#lineTo

.bezierCurveTo( cpX, cpY, cpX2, cpY2, toX, toY )

See PIXI.Graphics#bezierCurveTo

.quadraticCurveTo( cpX, cpY, toX, toY )

See PIXI.Graphics#quadraticCurveTo

.arcTo( x1, y1, x2, y2, radius )

See PIXI.Graphics#arcTo

.arc( cx, cy, radius, startAngle, endAngle, anticlockwise )

See PIXI.Graphics#arc

.drawShape( shape )

See PIXI.Graphics#drawShape

.clear()

Clear the path.

.closed

Set true to close your path.

.length

Get the points number

Tween

constructor( target [,manager] )

The constructor

.target

The object to animate

.manager

The TweenManager who manage this tween

.time

The animation time

.active

Read only, true if a tween is running

.easing

A easing function from PIXI.tween.Easing or a custom easing.

.expire

Set true if you want to delete this instance when the animation it's done.

.repeat

Times to repeat this tween.

.loop

Repeat this tween forever.

.delay

Set a delay time in milliseconds before the timer's count.

.pingPong

Set true to repeat back this tween.

.isStarted

Read only.

.isEnded

Read only.

.path

Set an instance of TweenPath to animate an object along the path.

.pathReverse

Reverse the path.

.addTo( manager )

Add this tween to a manager

.chain( tween )

When this tween it's finished, fire the chained tween.

.start()

Start the tween

.stop()

Stop the tween

.to( object )

Set the params to animate. Example: {x:100, y:100}

.from( object )

Set the params to start the animation. If you don't call .from the the values will be the actual values of the .to object.

.remove()

Remove this tween from the manager.

.clear()

Clear this tween.

.reset()

Reset this tween to the initial state, keeping the data like .time, .delay, etc...

update( delta [,deltaMS] )

The update method, you don't need to use this method, the manager will do this internally.

Easing

See Easing