Giter Club home page Giter Club logo

spriterhaxeengine's Introduction

SpriterHaxeEngine

The point of this project is to offer a Brashmonkey's Spriter SCML renderer compatible with Haxe 3 and openfl. Base code of SCML definitions from http://www.brashmonkey.com/ScmlDocs/ScmlReference.html

Inspired by

Install: haxelib install SpriterHaxeEngine

Choose your drawing library:

/**
* Example with the TilemapLibrary which uses openfl-atlas (haxelib install openfl-atlas)
*/
//set the root canvas where to add all the animations
var spriterRoot:Sprite = new Sprite();
addChild(spriterRoot);
//get an atlas
var tileset:TilesetEx = new SpriterTileset(Assets.getBitmapData('assets/atlas.png'), Assets.getText('assets/atlas.xml'));
//choose a rendering method.
var lib = new TilemapLibrary([tileset], spriterRoot, stage.stageWidth, stage.stageHeight);

/**
* Example with the BitmapLibrary which uses BitmapData.copypixels() and BitmapData.draw()
*/
//set the root canvas where to add all the animations
var canvas:BitmapData = new BitmapData(800, 480);
var spriterRoot:Bitmap = new Bitmap(canvas, PixelSnapping.AUTO, true);
addChild(spriterRoot);
//choose a rendering method.
var lib:BitmapLibrary = new BitmapLibrary('assets/', canvas);

/**
* Other libraries exist to use Spriter with flixel and other rendering method!
*/

Instantiate the engine:

//Create the engine.
//you can specify a default scml or you can specify it later in addSpriter()
engine = new SpriterEngine(Assets.getText('assets/test.scml'), lib );
		
//Add a Spriter in the engine. A Spriter contains all data from the scml (all entities, animations, boxes, tags...)
//By default, it will play the first animation of the first entity of your scml
engine.addSpriter('uniqueId', x,  y);

//Set the "run" animation of the entity
engine.getSpriter('uniqueId').playAnim('run', myCallback);

//Apply the "gun" map of the entity
engine.getSpriter('uniqueId').applyCharacterMap('gun', true);

//Update on enter frame to draw all Spriters on screen
engine.update();

//Callback on end anim
function myCallback(s:Spriter):Void

//callback
engine.getSpriterAt(0).onVarChanged = function varCallback(name:String, value:Dynamic):Void{}
engine.getSpriterAt(0).onEvent = function eventCallback(name:String):Void{}
engine.getSpriterAt(0).onSound = function soundCallback(name:String):Void{}

//current points and boxes
var points:Array<SpatialInfo> = engine.getSpriterAt(0).points;
var boxes:Array<Quadrilateral> = engine.getSpriterAt(0).boxes;

//current tags
var tags:Array<String> = engine.getSpriterAt(0).tags;

//current variables values
var value:Dynamic = engine.getSpriterAt(0).getVariable('myVar');


//stack anims
engine.getSpriter('uniqueId').playAnimsStackFromEntity("entityName", ["anim1","anim2"], myCallback).

Spriter Haxe Engine Features

SCML API

Engine

  • Can be overrided to fit your need
  • simple z-ordering
  • Fixed tick, variable tick or use your own time
  • Pause
  • simple auto removal
  • default scml

Spriter entity

  • character mapping by name
  • change animation easily by name in a Spriter entity
  • callback when animation ended
  • play, stack anim, pause
  • you can display duplicate of spriter entity and manipulate them separatly
  • callback when events, sounds are triggered
  • callback when variables change
  • Points (usage example : to shot a bullet when gun fire)
  • Boxes (usage example : hitbox)
  • Tags (usage example : state vulnerable)
  • sub entities
  • playing backward and reflect

Libraries

  • TilemapLibrary (use openfl tilemap, dependency: openfl, openfl-atlas)
  • Simple bitmap library (bitmaps handled with addChild, dependency : openfl)
  • BitmapData library (copypixels, dependency : openfl)
  • Tilelayer library (drawTiles using only one tilesheet)(dependency : openfl-tilelayer and openfl).
  • DrawTiles library (using many tilesheets)(dependency : openfl-tilelayer and openfl).
  • Flixel Library (atlas support or bitmaps handled with addChild, dependency : flixel) by Zaphod
  • Heaps Library (h3d/heaps, dependency : heaps ) by Delahee
  • Luxe Library (dependency : luxe )
  • override the AbstractLibrary to provide a new library

Other features

  • own texture packer exporter
  • macro to parse scml into binaries

Cross-platform

  • flash
  • windows
  • neko
  • android
  • html5

TODO

WIKI

The wiki provides more details on features and how it works.

Examples

Additional information

  • compatible with Spriter r6.1
  • With Tilelayer library, don't use openfl-bitfive for html5 target.

Known issues

  • Please use the best rendering method according to your target.

spriterhaxeengine's People

Contributors

beeblerox avatar delahee avatar loudoweb avatar sruloart avatar tbrosman 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

Watchers

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

spriterhaxeengine's Issues

Cache SCML's to binary to save loading time (if that's possible)

Like this Bardbarian's guys trick (later in the thread): http://forum.starling-framework.org/topic/json-or-xml: "what we did with Bardbarian: With over 30 SCML files to load, it was starting to get really slow. So we just added some code to our startup, to cache them all in a binary file.
Just make a big hash of all your StarlingAnimation instances, then use writeObject to store in a bytearray, and save to a little file "animations.bin".
When on the device, load the bin file, and extract each animation. Load times go from like 3000ms, to 10ms [:D]

WRITE:
var f:File = AirUtils.projectFolder.resolvePath("src/assets/spriter/scmlCache.bin");
var ba:ByteArray = new ByteArray();
ba.writeObject({sd: animationsByName, hd: animationsByNameHd});
ba.compress();

var fs:FileStream = new FileStream();
fs.open(f, FileMode.WRITE);
fs.writeBytes(ba, 0, ba.bytesAvailable);
fs.close();

READ:
var ba:ByteArray = new ByteArray();
var stream:FileStream = new FileStream();
stream.open(cacheFile, FileMode.READ);
stream.readBytes(ba, 0, stream.bytesAvailable);
stream.close();
ba.uncompress();
animationsByName = scale == 1? ba.readObject().hd : ba.readObject().sd; "

playAnimsStack problem when using looping animation

When using a looping animation in a sequence of animations with playAnimsStack(), the transition is not smooth. However the very same sequence with the animation set to looping false is smooth.

So we need to see why the transition is incorrect between a looping animation and an other animation on the playAnimsStack function.

pooling

Pooling will be a great improvement. I began to implement it (5443ab4)

When all objects that are instanciated many times per frames will be ready for pooling, it will be great to use typedef or something else to fallback to a specific pooling system from a framework (flixel, flambe, etc.)

Placement is off.

Placement is off. It's consistently off on all targets (Neko, HTML5, CPP) except Flash, where it's still off by a pixel but to the right instead of the left. It may not make a difference in large images, but in pixel art, being off by one pixel is a lot.

This happens on both the SpriterLibrary and the FlixelLibrary so I don't think it has anything with the library implementation.

http://i.imgur.com/az53Euf.png
az53euf

proposition : adding alpha with BitmapLibrary.hx

not very optimised, but it can make the deal in some cases :

if(spatialResult.angle == 0 && spatialResult.scaleX == 1 && spatialResult.scaleY == 1 && spatialResult.a==1)
{
_point.x = spatialResult.x;
_point.y = spatialResult.y;
_canvas.copyPixels(bmp, bmp.rect, _point,true);
}
else
{
_matrix.identity();
_matrix.scale(spatialResult.scaleX, spatialResult.scaleY);
_matrix.rotate(SpriterUtil.toRadians(SpriterUtil.fixRotation(spatialResult.angle)));
_matrix.translate(spatialResult.x, spatialResult.y);
_canvas.draw(bmp, _matrix, new ColorTransform(1,1,1,spatialResult.a), null, null, true);
}

Cannot get the points of an entity

I'm using this code to get the spriter:

            headSpriter = PlayState.instance.engine.addSpriter("head",X,Y);
    headSpriter.info.x = FlxG.width *0.75;
    headSpriter.info.y = -FlxG.height * 0.75;

To play:

    headSpriter.playAnimFromEntity("cabeza", "transicionAIdleCabeza", toIdleAnim, true);

On update I want to get the list of points and place eyes over them:

    var points:Array<SpatialInfo> = headSpriter.getPoints();
    var point:SpatialInfo;
    for (i in 0...points.length)
    {
        point = points[i];
        var eye = arrayEyes[i];
        eye.setPosition( point.x,   point.y);
    }

But the eyes are not showing where they suppose to go.

add scml b7 support

This engine is compatible with scml made with Spriter b6.1.
It needs now compatibility with scml b7 since Brashmonkey released a new version of Spriter few days ago.

cannot tileImages with TileLayerLib when targeing Windows, or Android

example---
If you try to put spriter objects side by side like in a tile map on windows or android. you will see a noticeable gap between the images. publishing to htlm5 or flash does not have this problem.

I have tested this with bitmapLib and SimpleBitmapLib. and they work fine. the problems seems to only occur when using the TilelayerLib

Easing tween implementation?

Hi! While playing around with a test animation, I noticed that the the easing tween between frames in Spriter aren't working/implemented yet. Animation tweens only play in a linear way.

Some bone animations explode

I think this is derived from bug #23

I made a demo with a stripped version of the platformer I'm making to test the animations using HaxeFlixel and the demo animations from spriter:

https://dl.dropboxusercontent.com/u/24695185/HaxeFlixelSpriterTest.rar

Some of the animations "explode" when are playing.

For the project I'm using the latest dev flixel and SpriterHaxeEngine. Notice that I added _dev to the names of the libraries.

@sruloart, maybe we can use this demo for HaxeFlixel when the issues are fixed?

Flip Animation

Hello,

I'm trying to implement spriter with HaxeFlixel using SpriterHaxeEngine.
The problem I encountered is that I can't flip the spriter sprites.

I tried this:

if (flipX)
{
//spriterAnims.info.scaleX = -1;
spriterAnims.info.scaleY = -1;
}
else
{
//spriterAnims.info.scaleX = 1;
spriterAnims.info.scaleY = 1;
}

But id does crazy things. Is there any solution?

Compatibility problem with haxe 3.4.0

The following error is not letting me compile using the latest Haxe:

C:/HaxeToolkit/haxe/lib/SpriterHaxeEngine/2,0,0/spriter/definitions/Metaline.hx:9: characters 9-38 : Warning : Structures with new are deprecated, use haxe.Constraints.Constructible instead

Animation of Subentities aren't played

Reference file for reproducing the bug is available here

Expected output of engine.getEntity('test').playAnimFromEntity('scene', 'MoveAnimation') (Due to technical issue, the gif below is playing slower than it should):

However, the runtime cannot animate the subentities. Here is the actual output

Notice that the blue balls don't rotate as it should.

addParticule (unique anim without loadings others from the SpriterEntity obj)

I use Spriter only for particules in my game, so in my SCML file, I have juste one entity with all the particules animations.

When I add an particule to the game (new Spriter obj to the SpriterEngine obj), I suppose creating a particule (new Spriter obj) copy all the SCML animations just for using one of them.

What do you think of the possibility to create a light particule Spriter obj with a unique specified animation (with autoDestroy boolean parameter) ?

Maybe like that :

function addParticule(_entity:String, _animation:String, _autoDestroy:Bool):Spriter
{}

Curve Type of Key inside Mainline is not Loaded

curveType is only loaded when the <key> is inside <timeline>.

When curveType is inside <mainline>, it isn't loaded. EDIT: and the curveType follows the one specified in <key> inside <timeline>.

Version of runtime: haxelib

EDIT: interestingly, curveType of MainlineKey isn't specified in the scml reference. But the editor is generating mainline key with curveType as of R5. And the behavior of the editor is that the curveType of MainlineKey overrides TimelineKey. Maybe time to ask the guys in BrashMonkey for explanation?

EDIT: I've checked their C++ reference implementation. Their MainlineKey has a TimeInfo, which has an EasingCurveInterface. Their EasingCurveInterface is inherited by implementation of curve, such as InstantEasingCurve and CubicEasingCurve. Therefore, their MainlineKey is indeed capable for storing curveType. Maybe their scml documentation is outdated?

<FIX> extra bracket causing case not found.SpriterAnimation.hx line 75

public function setCurrentTime(newTime:Int, library:AbstractLibrary, root:IScml):Void
{
var currentTime:Int;
var loop:Int;
switch(loopType)
{
case LOOPING:
loop = Std.int(newTime / length);
currentTime = newTime % length;
//callback
if (loop == 1){ <---remove bracket------!!!!!!!!!!
root.onEndAnim(name);

    case NO_LOOPING:
        currentTime = Std.int(Math.min(newTime, length));
        //callback
        if (currentTime == length)
            root.onEndAnim(name);
    }

add Context to Spriter/Libraries

Context could allow to let users define specific shader or other custom data to a Spriter character and use it in their custom Rendering Libraries.

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.