GithubHelp home page GithubHelp logo

hustcc / pixi-action Goto Github PK

View Code? Open in Web Editor NEW
66.0 7.0 17.0 644 KB

:horse_racing: pixi-action is a plugin for Pixi.js to create actions and animations easily, inspired by Cocos2d-x.

Home Page: http://git.hust.cc/pixi-action/

License: MIT License

HTML 68.87% JavaScript 28.52% CSS 2.61%
pixi pixi-action animation actionmanager cocos2d cocos2d-x rotation elapsedtime tint

pixi-action's Introduction

pixi-action

pixi-action is a plugin for Pixi.js to create actions and animations easily. API inspired by Cocos2d-x. Online demo here.

Build Status npm npm npm

1. Install

npm install pixi-action

require it, or import it with script tag, all is OK.

2. Usage

Code just like below.

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

var cat = new Sprite(resources['res/img/animal.png'].texture);

// here is the action define.
// similar with cocos2d-x.
var action_move = new PIXI.action.MoveTo(500, 400, 2);
// run the action with actionManager.
var animation = PIXI.actionManager.runAction(cat, action_move);
// listen the event, include: start, end.
animation.on('end', function(elapsed) {
  console.log('action end.');
});

function animate() {
  window.requestAnimationFrame(animate);
  renderer.render(stage);
  PIXI.actionManager.update(); // update actions
}
animate();

Action defines are similar with cocos2d-x.

3. How it works

This plugin add a new namespace named action to the PIXI namespace, and the action namespace has 2 new classes, ActionManager and Action, and create an instance for ActionManager in PIXI.actionManager, but all you need is add PIXI.actionManager.update() in your requestAnimationFrame. You can pass as params for PIXI.actionManager.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 action is started, or ended, it will fire events named start / end.

4. 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 timer.update in the raf.
animationLoop.on('postrender', function() {
  PIXI.actionManager.update(this.delta); //Pass as param the delta time to PIXI.timerManager.update
});

animationLoop.start();

5. Events

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

  • start - callback(elapsedTime): Fired when the action starts.
  • end - callback(elapsedTime): Fired when the action is ended.

6. Actions & Animations

Now pixi-action supported actions / animations below. You can just combine them for complex actions.

  • ActionMove

PIXI.action.MoveTo(x, y, time); PIXI.action.MoveBy(x, y, time);

  • ActionScale

PIXI.action.ScaleTo(x, y, time); PIXI.action.ScaleBy(x, y, time);

  • ActionRotate

PIXI.action.RotateTo(rotation, time); PIXI.action.RotateBy(rotation, time);

  • ActionBlink

PIXI.action.Blink(count, time);

  • ActionFade

PIXI.action.FadeIn(time); PIXI.action.FadeOut(time);

  • ActionSkew

PIXI.action.SkewTo(x, y, time); PIXI.action.SkewBy(x, y, time);

  • ActionPivot

PIXI.action.PivotTo(x, y, time); PIXI.action.PivotBy(x, y, time);

  • ActionTint

PIXI.action.TintTo(tint, time); PIXI.action.TintBy(tint, time);

  • ActionAlpha

PIXI.action.AlphaTo(alpha, time); PIXI.action.AlphaBy(alpha, time);

  • ActionSequence

PIXI.action.Sequence(actions);

  • Spawn

PIXI.action.Spawn(actions);

  • ActionRepeat

PIXI.action.Repeat(action, count);

  • repeatForever

PIXI.action.Repeat(action);

  • ActionDelay

PIXI.action.DelayTime(time);

  • ActionCallFunc

PIXI.action.CallFunc(func);

7. API

  • PIXI.actionManager.runAction(object, action): run action on an object, return an animation, can on the events.
  • PIXI.actionManager.cancelAction(AnimationObject): cancel the animation.
  • new PIXI.action.*(args): create an action.

LICENSE

MIT@hustcc. Welcome to Submit Pull Request.

pixi-action's People

Contributors

fabionuno avatar hustcc avatar kk167 avatar yjwong avatar zprodev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pixi-action's Issues

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.