Coder Social home page Coder Social logo

egret-spine's Introduction

egret-spine

A spine runtime for Egret (Demo: https://fightingcat.github.io/egret-spine/example in progress...).

Installing

Considering that Egret doesn't use module, neither does official spine core runtime, this runtime doesn't either, for now.

See Egret document for integrating to Egret project.

Or just include the .js file in HTML, if you only intend to build for web, like:

<script src="libs/egret-spine.js"></script>

Getting started

This implementation doesn't involve resource downloading, your actual code may varies from this boilerplate.

function loadImage(url: string): Promise<egret.Texture> {
    return new Promise(resolve => {
        let loader = new egret.ImageLoader();
        let texture = new egret.Texture();

        loader.once(egret.Event.COMPLETE, () => {
            texture.bitmapData = loader.data;
            resolve(texture);
        }, null);

        loader.load(url);
    });
}

function loadText(url: string): Promise<string> {
    return new Promise(resolve => {
        let request = new egret.HttpRequest();
        request.responseType = egret.HttpResponseType.TEXT;
        request.open(url, 'GET');
        request.send();
        request.once(egret.Event.COMPLETE, () => {
            resolve(request.response);
        }, null)
    });
}

async function runDemo() {
    let json = await loadText('assets/demo.json');
    let atlas = await loadText('assets/demo.atlas');
    let texAtlas = spine.createTextureAtlas(atlas, {
        "demo.png": await loadImage('assets/demo.png')
    });
    let skelData = spine.createSkeletonData(json, texAtlas);

    let animation = new spine.SkeletonAnimation(skelData);

    animation.play('animation');
    egret.lifecycle.stage.addChild(animation);
}

runDemo();

More example code.

Learn more

Several classes or structures have been added, all be declared within namespace spine to minimize impact.

  • createSkeletonData Helper for creating skeleton data.
  • createTextureAtlas Helper for creating texture atlas.
  • SkeletonAnimation A user-friendly animation manager.
  • SkeletonRenderer A mere skeleton renderer
  • SlotRenderer Slot renderer for SkeletonRenderer.
  • EventEmitter Embbeded implemation of event emitter.
  • SpineEvent Enums of animation events.
  • Track Track abstraction for SkeletonAnimation.

egret-spine's People

Contributors

fightingcat 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

egret-spine's Issues

can't work with egret

maybe my problem, I just download the zip file and using wing 3 to open the folder.
Seems can't run...

I am new to egret, Could you please make a workable project as an example?

Thank you very much

Egret 5.3.10 Can not use

Egret 5.3.10 Can not use, can you please take a look or add an example project to show how to use?

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.