Giter VIP home page Giter VIP logo

pixi-spine's Introduction

pixi-spine

Spine 3.7, 3.8, 4.0, 4.1 implementation for PixiJS v5 & v6.

Typescript definitions are up-to-date with PixiJS v6.

For spine < 3.7 support is limited, but accepting PR's for runtime-3.7 package.

For previous versions of pixi & typescript definitions - please refer to README in pixi5

Demos:

https://pixijs.io/examples/#/plugin-spine/spineboy-pro.js

https://pixijs.io/examples/#/plugin-projection/runner.js

https://sbfkcel.github.io/pixi-spine-debug/

Basic Usage

Please read this carefully: there are three ways to add this lib to your app.

  1. Angular, React, Webpack, Rollup - if you know those words, use ES6 bundles
  2. Good old <script src="pixi-spine.umd.js"> , also named vanilla JS
  3. Custom bundle, for guys who really want to shake da tree

ES6 bundles

import * as PIXI from 'pixi.js';
import {Spine} from 'pixi-spine';

const app = new PIXI.Application();
document.body.appendChild(app.view);

app.loader
    .add('spineCharacter', 'spine-data-1/HERO.json')
    .load(function (loader, resources) {
        const animation = new Spine(resources.spineCharacter.spineData);

        // add the animation to the scene and render...
        app.stage.addChild(animation);
        
        if (animation.state.hasAnimation('run')) {
            // run forever, little boy!
            animation.state.setAnimation(0, 'run', true);
            // dont run too fast
            animation.state.timeScale = 0.1;
        }
        
        app.start();
    });

Alternatively, you may use @pixi-spine/all-3.8 package.

Where are spine core classes?

Classes like AttachmentType, TextureAtlas, TextureRegion and Utils are shared across all spine versions, and re-exported by all bundles. But if you want to see them directly, they are in @pixi-spine-base.

Base also contains unified interfaces, ISkeleton, ISkeletonData, IAnimationData and so on, see ISkeleton.ts file.

Most of classes are spine-version-dependant, including Skeleton, SkeletonData, they are stored in corresponding packages @pixi-spine/runtime-3.8 and so on.

Vanilla JS, UMD build

All pixiJS v6 plugins has special umd build suited for vanilla.
Navigate pixi-spine npm package, take dist/pixi-spine.umd.js file. Alternatively, you can look in @pixi-spine/all-3.8 npm package.

<script src='lib/pixi.js'></script>
<script src='lib/pixi-spine.umd.js'></script>
const animation = new PIXI.spine.Spine(resources.spineCharacter.spineData);

Unfortunately, there are no typescript definitions for vanilla build on both pixi v6 and pixi-spine

Custom bundle

Main bundle pixi-spine weights more than 1 MB.

Bundle @pixi-spine/all-3.8 weights about 400 KB.

If you want to use different version (3.7) please look how modules loader-3.8 and pixi-spine-3.8 are made.

Basically, you have to copy its code in a separate file in your project, and alter imports to corresonding version.

For example, here's bundle for 3.8:

import {SpineParser} from '@pixi-spine/loader-3.8';
export {SpineParser};
export * from '@pixi-spine/runtime-3.8';
export * from '@pixi-spine/base';

SpineParser.registerLoaderPlugin();

In case author was too lazy to publishloader-3.7, you can do the same trick with them, just look in sources of loader-3.8.

Want to go advanced?

Read our docs.

Two-color tint

Light-dark tint is supported with help of pixi-heaven Currently supported only by UMD build.

let spine = new PIXI.heaven.Spine(spineData);

Debug

To show bones and bounds you can use pixi-spine-debug. If you want to write your own debug plugin, look at how this one was created

Demo: https://sbfkcel.github.io/pixi-spine-debug/

Build & Development

You will need to have node setup on your machine.

Make sure you have rush installed:

npm install -g @microsoft/rush

Then you can install dependencies and build:

npm run prepare
npm run build

That will output the built all modules. UMD can be found in ./bundles/pixi-spine/dist.

If you use IntellIJ Idea / Webstorm to navigate the project, take this line and set it in project settings / exclude files

packages/*/node_modules;packages/*/compile;bundles/*/node_modules;bundles/*/compile;lib;dist

pixi-spine's People

Contributors

ivanpopelyshev avatar cursedcoder avatar englercj avatar elizavetta avatar jonlepage avatar simontadram avatar liamf1986 avatar gprzybylowicz avatar exponenta avatar zprodev avatar pawelstan avatar themoonrat avatar probityrules avatar qwertykg avatar congtung10t2 avatar rblstr avatar lloydevans avatar jmlee2k avatar unclearriw avatar gurmukhp avatar patrick-hammond avatar knifhen avatar abhishekrathore03 avatar zk-luke avatar finscn avatar arksu avatar smlmyck avatar paolotozzo avatar mattostgard avatar goodboydigital avatar

Stargazers

 avatar

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.