Git Product home page Git Product logo

spine's Introduction

pixi-spine

Spine 3.7, 3.8, 4.0, 4.1 implementation for PixiJS.

Versions Compatibility

PixiJS pixi-spine
v5.x - v6.x v3.x
v7.x v4.x

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

For previous versions of pixi refer to

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 many ways to add this lib to your app.

  1. npm, Webpack, Rollup, Vite - if you know those words, use npm i pixi-spine
  2. Good old <script src="pixi-spine.js">, also named vanilla JS
  3. The modern <script type="module" src="pixi-spine.mjs">, for ES modules
  4. Single version, check the all-X.Y bundles
  5. Custom bundle, for specific combinations of versions.

Bundles example

import 'pixi-spine' // Do this once at the very start of your code. This registers the loader!

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

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

PIXI.Assets.load("spine-data-1/HERO.json").then((resource) => {
	const animation = new Spine(resource.spineData);
    app.stage.addChild(animation);

    // 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;
        // update yourself
        animation.autoUpdate = true;
    }
});

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.

Browser builds

For browser builds, you will need to grab either the .js (for CJS) file or the .mjs (for ESM) from the dist folder or from your CDN of choice.

Custom bundle

Main bundle pixi-spine weights 374 KB (unzipped).

Bundle @pixi-spine/all-3.8 weights about 165 KB (unzipped).

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 corresponding version.

For example, here's bundle for 3.8:

import '@pixi-spine/loader-3.8'; // Side effect install the loader
// eslint-disable-next-line @typescript-eslint/no-duplicate-imports
export * from '@pixi-spine/runtime-3.8';
export * from '@pixi-spine/base';

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. (and most likely on PixiJS < 7.x)

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

Debug

To show debug graphics you can set yourSpine.debug = new SpineDebugRenderer()

Control what gets drawn with the following flags:

// Master toggle
yourSpine.debug.drawDebug = true; 

// Per feature toggle
yourSpine.debug.drawMeshHull = true;
yourSpine.debug.drawMeshTriangles = true;
yourSpine.debug.drawBones = true;
yourSpine.debug.drawPaths = true;
yourSpine.debug.drawBoundingBoxes = true;
yourSpine.debug.drawClipping = true;
yourSpine.debug.drawRegionAttachments = true;

To have even more control, you can customize the color and line thickness with

yourSpine.debug.debugOptions.lineWidth = 1;
yourSpine.debug.debugOptions.regionAttachmentsColor = 0x0078ff;
yourSpine.debug.debugOptions.meshHullColor = 0x0078ff;
yourSpine.debug.debugOptions.meshTrianglesColor = 0xffcc00;
yourSpine.debug.debugOptions.clippingPolygonColor = 0xff00ff;
yourSpine.debug.debugOptions.boundingBoxesRectColor = 0x00ff00;
yourSpine.debug.debugOptions.boundingBoxesPolygonColor = 0x00ff00;
yourSpine.debug.debugOptions.boundingBoxesCircleColor = 0x00ff00;
yourSpine.debug.debugOptions.pathsCurveColor = 0xff0000;
yourSpine.debug.debugOptions.pathsLineColor = 0xff00ff;
yourSpine.debug.debugOptions.skeletonXYColor = 0xff0000;
yourSpine.debug.debugOptions.bonesColor = 0x00eecc;

You can reuse a single debug renderer and they will share the debug settings!

const debugRenderer = new SpineDebugRenderer();

oneSpine.debug = debugRenderer;
anotherSpine.debug = debugRenderer;

If you want to create your own debugger you can extend SpineDebugRenderer or create a class from scratch that implements ISpineDebugRenderer!

Build & Development

You will need to have node setup on your machine.

Then you can install dependencies and build:

npm install
npm run build

That will build all packages and bundles. Browser packages are inside dist and npm packages are inside lib

npm link will misbehave because of the monorepo setup.

Deploying

If you have enough rights to publish this monorepo, you can publish by running npm run lernaPublish This is so that it runs with the internal npm v8 since npm v9 doesn't play nice with Lerna.

If for some reason your publish failed, use npm run lernaPublish:fromPackage to try to force a publish without creating a new version

spine's People

Contributors

abhishekrathore03 avatar arksu avatar congtung10t2 avatar cursedcoder avatar elizavetta avatar englercj avatar exponenta avatar finscn avatar gprzybylowicz avatar gurmukhp avatar ivanpopelyshev avatar jmlee2k avatar jonlepage avatar knifhen avatar liamf1986 avatar lloydevans avatar miltoncandelero avatar paolotozzo avatar patrick-hammond avatar pawelstan avatar probityrules avatar qwertykg avatar rblstr avatar serg-y avatar simontadram avatar smlmyck avatar themoonrat avatar unclearriw avatar zk-luke 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spine's Issues

Playing multiple animations at once?

Hi y'all,

I was wondering how to play two animations (this is a question, not bug report). Particularly, I want to set multiple animation states and update them separately. So for example:


        bunny.update(0);
        bunny.autoUpdate = true;

        bunny.state.setAnimationByName(0, 'idle', true);        
        bunny.state.setAnimationByName(1, 'growth', true); 

so here's the specific questions:

  1. How do I set track 1 of the animation to autoUpdate = false while tracks 0 is autoUpdate = true? Do I have to set the overall bunny.autoUpdate = false and then just manually update each animation?
  2. How do I manually update the position of a single track and not bunny as a whole? Particularly, I'd like to set it to a certain % of the animation state. So I don't necessarily need to set it to specifically 2 seconds, but just to the halfway mark of the animation (whatever it may be).
  3. Are there any docs on .update()? What options do I have?

goto delta time (question not issue)?

Hi not really an issue just a question. Is there a way to jump to a specific time/delta. I'm looking in the AnimationState.js but can't see what to use.

Thanks

Constraint problems

Having strange behaviour when using Constraints. Especially with chained/interconnected constraints.
The sprites get rotated and are not inline with the original animation.
Tried to have all constraints on the root node and it is working better, but there are still issues with positioning and rotation.

I've tried the same animation with Esoterics Spine JS runtime and everything is working with it.

Setup a test project available at http://bugs.kodbyran.se/pixi-spine-20150519

The spine source files is available on
http://bugs.kodbyran.se/pixi-spine-20150519/spine-animation_20150519_01.zip

I'm using the latest pixi and pixi-spine (master branches)

screen shot 2015-05-19 at 11 20 36

Filters dont work?

       loader.use(PIXI.spine.loaders.atlasParser())
                        .add('raptor','../spine/path/to/.json');    

        loader.on('complete',function(loader,res){
            var bunny = new PIXI.Container();
            var spider = new PIXI.spine.Spine(res['raptor'].spineData);

            spider.position.x = 400;
            spider.position.y = 800;
            spider.autoUpdate = false;
            spider.skeleton.setSlotsToSetupPose();

            bunny.interactive = true;
            bunny.on("mouseover",function(e){
                var filter = new PIXI.filters.ColorMatrixFilter();
                bunny.filters = [filter];
                filter.brightness(1.4,false);
            });
            bunny.on("mouseout",function(e){
                bunny.filters = null;
            });

            bunny.on("click",function(e){
                alert("Clicked");                   
            }); 

            bunny.addChild(spider);

            // once position and scaled, set the animation to play
            spider.state.setAnimationByName(0, spider.spineData.animations[0].name, true);

//Hard set the filters
                var filter = new PIXI.filters.ColorMatrixFilter();
                bunny.filters = [filter];
                spider.filters = [filter];
                filter.brightness(1.4,false);

            bunny.addChild(spider);
            arena.addChild(bunny);
        });

I don't ever see any brightening on the Spine object. I put the filter on both the Spine object and the Container because I've tried both options individually and neither seemed to work

How to use pixi-spine and pixi v3 with require.js

After the upgrade, when we build the project using grunt-contrib-requirejs all goes well, however when we load it in the browser we get:

Uncaught ReferenceError: PIXI is not defined

So, after trying many things, we haven't been able to fix it and was wondering if somebody can provide a example of how to you pixi-spine with require.js.

This is how we have our require-config.js

shim: {
....
'PIXI': { exports: 'PIXI'},
....
},
paths: {
....
'PIXI': '../../node_modules/pixi.js/bin/pixi',
'spine': '../../node_modules/pixi-spine/bin/pixi-spine',
....
}

where to attach shaders to individual limbs?

@ivanpopelyshev I'm messing around with adding dynamic lighting to spine2d for use with pixi. I'm thinking the easiest way to start with this is to attach shaders to individual elements of these spine instances. e.g., if i want to attach a shader to the sprite representing a skeleton's arm, where in the data structure should I do this?

please push 1.0.4 to npm

I'm using 1.0.3 from npm and getting a lot of deprecation warnings about PIXI.math. I'm pretty sure 1.0.4 fixes this?

Incorrect placement of spine images

I have simple frame by frame animation that I was testing using spine and pixi and discovered a bug that makes the animation look shaky. Pixi is getting the images from the atlas file generated from spine, though the zipped project includes the individual images for the spine project.

Canvas renderer broken with renderer.resolution != 1?

It appears the spine rendering is broken in the combination of a canvas renderer and the renderer.resolution set to anything other than 1.

The WebGL renderer works beautifully with non-unity resolutions and the canvas renderer does an amazing job when resolution is 1. But when it is something else, it appears placement of some sprites/meshes is multiplied by the resolution factor, causing the animation to be expanded (resolution > 1) or squashed (resolution < 1). Probably the fix only needs to divide by resolution.renderer 'somewhere'..

Changing SpineData/Texture of Spine object?

Hi, long time no chat :)

I was curious if there is a way to change what Spine atlas is associated with the Spine object. Essentially, just like I can do .texture = new Texture(); for Sprites, I want to know how to do that for Spines also

FlipX, FlipY issues

Hi,

There seems to be a problem with flips.
To reproduce:
-add a Flip_X key frame in an animation in the Spine editor
-export
-use pixi-spine.js to load and display animation

Note that the flip seems to do nothing.

Notes:
We are not using IK.

Thanks,
Darie

No longer require('pixi.js')

I've been forced to change the way pixi exports itself due to incompatibilities in what was done previously (see pixijs/pixijs@c9a89a8, and pixijs/pixijs#1713)

Previously we used expose and a manual AMD/static export. This meant our bundle would export a require function so you could require('pixi.js'). Unfortunately that would clobber the requirejs require in those environments and break it for those users.

Instead I must now use standalone which exports a normal UMD wrapper that will work for everyone. I've also added a static global export so that window.PIXI will always be exported. Without a better idea I suggest you update this repo to use PIXI as an implicit global, and do not require it since that will no longer work.

gulp-mocha missing

Hi think gulp-mocha is missing from your npm install json

Once I added to manually I could build the file fine.
Thanks

is there a usage example? this module isnt working for me

I'm trying to use pixi-spine as a commonjs module. I have [email protected] and install [email protected]. My code looks like this:

pixi = require 'pixi.js'
spine = require 'pixi-spine'


animation = new spine 'assets/spine.json'

this throws an error at run time:

Uncaught TypeError: object is not a function

Any idea why this won't work? While I appreciate have more modular includes, pulling this out of core pixi with no examples on how to use it is kind of rough. :/

SkinnedMeshRenderer

for objects with many MeshAttachments its crtitical to upload geometry to GPU only for the first time. Every frame upload only bones, mat3 per one bone.

drawArrays(gl.TRIANGLE_STRIP, attachment.startPosition, attachment.endPosition-attachment.startPosition);

Loading assets inline

Is it possible to not use the PIXI loader for assets, or somehow sidestep the ajax call?

I've tried to cut out the delay in the data loading over ajax by inlining the JSON object and atlas from Spine, but I can't get it to work.

Thanks.

Spine "src" Restructuring

Overview:

Spine.js & SpineRuntime.js would be broken down into a new "src" folder and their respective dir.

src/
  Spine/
  SpineRuntime/
Spine.js
SpineRuntime.js

then...

Spine/
  root.js
    ^ contains any bootstrapping type code
  Spine.js
    ^ contains the header code and @class/@module statement for documentation
  update.js
    ^ method
  autoUpdateTransform.js
    ^ method
  ...

Summary:

This would separate out all major methods and properties of both Spine and SpineRuntime making them easier to modify and update.

Usage:

  • Rather than one large single file, this would make many smaller files.
  • Each file would be either a method or a property

Implementation:

  • Option 1: Use a grunt tool to concat the files together.
    • This would be easy enough to use and a more basic implementation. Requires the files to be manually ordered in the Gruntfile.
  • Option 2: Use a require() type system making each sub file it's own module.
    • Would still require manual ordering in the Gruntfile, however would open up options for including other modules as sub modules of the plugin later on for added functionality.

Pixi.Spine without loader

Is there a workaround for generating a spine element without having to rely on the loader?
I already have a base64 encoded image and atlas+json data as a string stored in variables and would like to do something like this:
new PIXI.spine.Spine(base64EncodedImage, atlasAsString, jsonAsString);

Any help is appreciated!

an example of using a pixi mask with spine?

I'm trying to place a mask on a spine object, but I'm a bit confused due to the anchoring of spine objects being treated a bit differently. Can anyone shed some light on this?

IK Constraints

Hi,

I'm new to using Spine and PIXI and I was wondering if anyone was experiencing problems with using IK Constraints and capturing the characters bounds in runtime?

If I import the Goblin example the _bounds object and getLocalBounds function seem to have width and height properties but on my character containing IK everything is set to zero.

I am using the latest version which was compiled on June 7th.

Any help or workarounds would be greatly appreciated.

Incorrect Transparency Amount With Additive Slots

Attached is an image of the issue and a zip with files to reproduce the problem. It appears as if the color tinting is being applied twice to slots with additive blend modes and as a result a faded out slot can appear barely visible, while the same values when viewed in the spine editor it would still be clearly visible. The bottom two gradient bars is how it should look, the top is incorrect.

I created it by making 11 white sprites and tinting the alpha of each at increments of 10 percent and setting the blend mode to additive.

https://dl.dropboxusercontent.com/u/36289/xfer/2015/pixi-spine_additive_transparency_bug.zip
pixi-spine_additive_bug_sshot

pixi.Spine need 'destroy' function

hi ivan..

pixi.spine seems to need 'destroy function' because quick release by garbage collector

my game generated many effects realtime and than memory is up very quickly.

of course this will be released but it looks slow to control memory on Mobile..

because Mobile memory is so low specially iPhone

how do you think about this?

thx a lot

FFD Keyframe issue?

This is more or less a question wrapped in a possible bug report. Whenever I have vertices keyed in on the dopesheet in spine, as in only a handful of vertices, the animation won't play in pixi. More specifically, the layers with the mesh that has animated vertices do not appear. This also breaks all other spine animations that have a mesh in them (by making those layers disappear); similar to the bug I reported here #10 but without the WebGL warning. I just generally want to know if anyone has experienced the same thing and whether the issue is more likely error rooted in Spine, Pixi, or the application I am developing.

I am using pixi 3.0.6 and the latest pixi-spine

Getting to original state

Hi, we have switched from Phaser and implemented Spine into our games and we have drastically reduced our asset sizes so thank you very much!

We want to play an animation then reset it back to how it looks when the asset was first loaded, before the animation was played, or the very first spine state of the animation. I can't see any methods for doing this yet.

Is there an any way to do this? We are currently having to destroy and recreate so we can't pool our objects.

Pixi-Spine Documentation @ some.github.io/pixi-spine/docs

This the next major project that I will be working on concerning pixi-spine.

The concept is to go through and detail all of the pixi-spine plugin as to what each class, method, and property does, with detailed documentation.

Changes:

  • Use yuidoc instead of jsdoc
    • Though yuidoc may be less accurate, the intent for this project is to set up the docs as to what the pixi-spine plugin should work/read like, rather than how it currently does. (as there may be numerous changes later/ or soon).

Summary:
The intent overall for this would use documentation temporarily as more of an overall concept/thesis type deal, rather than real hardcore documentation that is exactly how it is in the code. So figure the documentation at first wouldn't be pushed to the public as the "where to go" for answers( as it would be a work in progress ). Though later it would be a valid source for detailed info.

Why yuidoc?
I'm suggesting yuidoc because it will separate documentation from the source code and allow for what the intent is to play out(conceptually frameworking what the source code should work like, read like, and have it's usage be). This loosens the need for source code to match up.

Down the road?
Once there is a framework laid out as to what pixi-spine is, my opinion is that more and more of it's flaws will be exposed and can thus be fixed much faster than currently. Where currently perhaps there is no direct all-encompassing solution for a problem( as solutions are getting done one by one and generally only relating to issues submitted ).

An Example

Would it be possible to include a basic working example .. I've tried the pixi V3 examples but can't get them to work any help would be great, I know everything is in heavy flux at the moment

Destroy method

I am using the method you showed me before to initialise my spine instances inline.

Is there a way I can remove the spine instances from the PIXI canvas once they have been created? I have searched the plugin for 'destroy' and other usual suspects but struggling to find the correct way.

Thanks.

Glitching on Stock Android

If you run a spine animation in the stock android browser (Samsung Phones/tablets) you will see the animation "glitches". It is random and affects animations differently but you can expect to see it's positions jump or the rotation jump and then back to normal.

I have tested the example from esoteric and it works fine so must be something in pixi. Also there is a createJS version that is based upon the pixi version that also works fine.

http://esotericsoftware.com/files/runtimes/spine-js/example/
http://www.patrickmatte.com/?p=450

ALso I have noticed in the demo "spineboy" when running in PIXI, the characters "right thigh" (near side) is not anchored correctly. It looks like it is anchored in the center but should be anchored at the top/character hip.

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.