Coder Social home page Coder Social logo

pixi-ease's Introduction

pixi-ease

a simple and powerful pixi.js easing/tweening/animating library

features

  • ease any pixi.js parameter, including tint (using a blend function or stepped)
  • use any Penner function by name or any user-defined function
  • support for generic number parameters
  • change scale or skew using one parameter (e.g., scale: 5 changes both scale.x and scale.y)
  • set default durations and easing function for all eases
  • uses eventemitter3 for events for both the easing lists and individual eases
  • tracks eases on DisplayObject and cleans up when DisplayObject is destroyed
  • includes a default easing list so you don't have to instantiate for simple cases
  • includes a shake parameter
  • good test coverage

Live Demo

https://davidfig.github.io/pixi-ease/

Migrating to v3

  • changed default update loop to use requestAnimationFrame to remove the dependency on pixi.js
  • to use PIXI.Ticker (like in v2), pass new Ease({ ticker: PIXI.Ticker.shared })
  • ordinary usage should be unchanged

Installation

yarn add pixi-ease

or grab the latest release and use it:

<script src="/directory-to-file/pixi.js"></script>
<script src="/directory-to-file/pixi-ease.js"></script>
<!-- or <script type="module" src="/directory-to-file/pixi-ease.es.js"></script> -->
<script>
    const ease = new Ease.Ease(options)
    Ease.add(...)
    // or Ease.ease.add(...)
</script> 

API Documentation

https://davidfig.github.io/pixi-ease/jsdoc/

Simple Usage

import * as PIXI from 'pixi.js'
import { Ease, ease } from 'pixi-ease'

const app = new PIXI.Application()
const test = app.stage.addChild(new PIXI.Sprite(PIXI.Texture.WHITE))
test.tint = 0x00ff00

const example = ease.add(test, { x: 20, y: 15, alpha: 0.25, rotation: 20, scale: 5, skewX: 0.25, blend: 0xff0000 } }, { reverse: true, duration: 2500, ease: 'easeInOutQuad' })
example.on('each', () => console.log('ease updated object during frame using PIXI.Ticker.'))
example.once('complete', () => console.log('move ease complete.'))

test.generic = 25
const generic = ease.add(test, { generic: 0 }, { duration: 1500, ease: 'easeOutQuad' })
generic.on('each', () => console.log(test.generic))

const secondEase = new Ease({ duration: 3000, wait: 1500, ease: 'easeInBack', repeat: 3 })
const test2 = app.stage.addChild(new PIXI.Sprite(PIXI.Texture.WHITE))
secondEase.add(test2, { tint: [0xff0000, 0x00ff00, 0x000ff], scaleX: 2 })

Build Examples

I've included a bunch of build examples in the builds directory, including: browserify, rollup, standalone (e.g., cdn), standalone (pixi.js v4), and typescript.

Tests

  1. Clone repository
  2. yarn install
  3. yarn test (for Mocha test code)
  4. yarn coverage (for Instanbul coverage)

To run demo locally:

  1. Clone repository
  2. yarn install
  3. yarn build
  4. yarn dev
  5. open browser to http://localhost:10001

To run build examples:

  1. Clone repository
  2. yarn install
  3. yarn build
  4. yarn builds
  5. yarn test-builds
  6. open browser to http://localhost:5000

Other Libraries

If you liked pixi-ease, please try my other open source libraries:

  • pixi-viewport - A highly configurable viewport/2D camera designed to work with pixi.js.
  • pixi-scrollbox - pixi.js scrollbox: a masked box that can scroll vertically or horizontally with scrollbars (uses pixi-ease)
  • intersects - a simple collection of 2d collision/intersects functions. Supports points, circles, lines, axis-aligned boxes, and polygons

License

MIT License (c) 2019 YOPEY YOPEY LLC by David Figatner

pixi-ease's People

Contributors

davidfig avatar zenblender 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  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

pixi-ease's Issues

Update animation

Wrong remove algorithm, it splice wrong elements if it can't find match. Really, how can you write code like that? I spend around a hour to understand wtf with my element and his animation. Maybe you add some checking?

My last element losing his animation, when index being -1
http://prntscr.com/pwqw8s

Type errors in EaseParams

Hello David,

I love your work and your pixi libraries are just awesome !
I found some errors just by opening your index.d.ts in pixi-ease.

ERROR in node_modules/pixi-ease/@types/index.d.ts:17:6 - error TS2411: Property 'position' of type 'Point | DisplayObject' is not assignable to string index type 'number'.

17      position?: PIXI.DisplayObject | PIXI.Point
        ~~~~~~~~
node_modules/pixi-ease/@types/index.d.ts:25:6 - error TS2411: Property 'face' of type 'Point | DisplayObject' is not assignable to string index type 'number'.

25      face?: PIXI.DisplayObject | PIXI.Point
        ~~~~
node_modules/pixi-ease/@types/index.d.ts:29:6 - error TS2411: Property 'tint' of type 'number | number[]' is not assignable to string index type 'number'.

29      tint?: number | number[]
        ~~~~
node_modules/pixi-ease/@types/index.d.ts:30:6 - error TS2411: Property 'blend' of type 'number | number[]' is not assignable to string index type 'number'.

30      blend?: number | number[]

This prevent me from using the production build inside the angular application I am working on. I am still a beginner concerning typescript so I have no clue about the cause of this error and this may be totally due to some local configurations.

Any thoughts about this ?

Animate pivot point

Currently there doesn't seem to be a way to animate the pivot/anchor. Is this possible?

My initial thoughts are it's more difficult due to the pivot/anchor values being objects rather than just a number on the element being eased.

Error when using ticker

When I set useTicker: true along with the ticker, it raised an error saying TypeError: undefined is not an object (evaluating 'this.ticker.elapsedMS').

How to stack multiple animations on same object in order

So I can't really figure out how to solve this problem.

So for example we have a very simple animation.
Object is initially at position A, then it moves to position B, waits 2s, and moves from position B to position C.

How do I have to configure animation list to get animation like that? Currently it always starts animation B->C from position A instead of B.

each loop event with repeat

import * as PIXI from 'pixi.js'
import { Ease, ease } from 'pixi-ease'

const app = new PIXI.Application()
const test = app.stage.addChild(new PIXI.Sprite(PIXI.Texture.WHITE))
const generic = ease.add(test, { alpha: 0 }, { duration: 1500, repeat: true, ease: 'easeOutQuad' })
generic.on('each', () => console.log(test.generic))

Docs are saying that: fires on each loop when there are eases running

But it fires on each tick (every frame).

So, how to catch an event when the current loop of repetitive animation is completed (event between each repetitive loop)?

List of ease functions?

I can't seem for the life of me to find an actual list of functions included (ie linear, easeInCubic )
Digging through the code shows some of them but its not a great way to go about it

support for es6

Thank you for providing this library,can you add support for import ,like import Ease from 'pixi-ease'

erros while compiling

Here is the error from the console

ERROR in node_modules/pixi-ease/@types/index.d.ts:63:5 - error TS2416: Property 'on' in type 'Ease' is not assignable to the same property in base type 'EventEmitter<string | symbol, any>'.
  Type '(event: "complete" | "each", fn: (ease: Ease) => void, context?: any) => this' is not assignable to type '<T extends string | symbol>(event: T, fn: (...args: any[]) => void, context?: any) => this'.
    Types of parameters 'event' and 'event' are incompatible.
      Type 'T' is not assignable to type '"complete" | "each"'.
        Type 'string | symbol' is not assignable to type '"complete" | "each"'.
          Type 'string' is not assignable to type '"complete" | "each"'.
            Type 'T' is not assignable to type '"each"'.
              Type 'string | symbol' is not assignable to type '"each"'.
                Type 'string' is not assignable to type '"each"'.

63     on(event: 'each' | 'complete', fn: (ease: Ease) => void, context?: any): this

Using latest version of pixi-ease, angular 9.
Are there any types to be installed for this error to go away?
Thanks

Update animation slice bug

When animation is completed and activates onComplete callback, which removes other animation array "list" and array this.easings becomes different. After that action list have an element which this.easing doesn't. After that coming splice with index -1 and removes wrong animation element

proofs
after we delete element animation
image
and now we deleting index -1, so wrong element lost animation
image

this.list[e].update is not a function

This happens for me after upgrading to 2.x. It seems to happen when easings are in progress and ease.removeAll() or ease.removeAllEases() is called.

this.list[e].update is not a function
    at update (/Volumes/Data/Workspace/touchtech/dsr-space-exploration/node_modules/pixi-ease/dist/ease.js:1)
    at TickerListener.emit (/Volumes/Data/Workspace/touchtech/dsr-space-exploration/node_modules/@pixi/ticker/lib/ticker.js:138)
    at Ticker.update (/Volumes/Data/Workspace/touchtech/dsr-space-exploration/node_modules/@pixi/ticker/lib/ticker.js:661)
    at Ticker._tick (/Volumes/Data/Workspace/touchtech/dsr-space-exploration/node_modules/@pixi/ticker/lib/ticker.js:367)```

"relative" or "proportional" option?

Hi!
I often need proportional/relative easing, e.g., for scaling of objects by a factor X instead of (absolute) scaling to a scale X.
Is this supported (I didn't find it)? or is this a desirable feature (e.g. as one more option to ease.add())?
Thanks!

Animations flicker after switching browser tabs.

It seems like after I come back to the tab after a while, animations have been "queued up" and all play at once resulting in their state switching from (seemingly) start to finish 10 times a second.

A temporary workaround for me is to remove all animations once the browser tabs "blur" event is called and then readd them once "focus" is fired. This results in a "lifeless" game when losing focus on the window. It becomes alive again once focus comes back at least so I guess this is "acceptable".

Is this avoidable otherwise? I am pretty sure my implementation was nothing too specific:

const animationList = new Ease.list()

animationList.to(graphic.scale, { x: 1.2, y: 1.2 }, 500, { ease: "easeInSine", repeat: true, reverse: true })

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.