Coder Social home page Coder Social logo

openfl-oasis's Introduction

openfl-oasis

Advanced 2D Sprite animation system for flash or openfl

What are the advantages of openfl-oasis?

  • It's interface driven (that means it's meant to be extendable)
  • It's super memory efficient. Only holds one reference to any given bitmap data
  • It's built on top of fair scheduling, which means it plays well with heavy load
  • Because it's built on top of scheduling you could implement your own scheduler and use threading
  • Works with texture packer

Sample setup:

package;


import schedule.FairTaskScheduler;
import schedule.TaskScheduler;
import animation.RunnableAnimation;
import animation.FrameFactoryAnimationClip;
import animation.TexturePackerFrameFactory;
import flash.display.Sprite;
import flash.text.TextField;
import flash.events.Event;
import flash.events.MouseEvent;
import haxe.Timer;
import haxe.Json;
import openfl.Assets;
import flash.display.Bitmap;
import flash.display.BitmapData;

class Main extends Sprite {

    private var _taskScheduler: TaskScheduler;

    public function new() {
        super();

        //create a scheduler to manager the frames
        _taskScheduler = new FairTaskScheduler();
        addEventListener(Event.ENTER_FRAME, onEnterFrame);

        //texture packer data
        var frameData: Dynamic = Json.parse(Assets.getText("assets/Lazlo_Walk_Side.json"));
        //source bitmap data
        var srcBd: BitmapData = Assets.getBitmapData("assets/Lazlo_Walk_Side.png");

        //The frame factory manages the individual frames for maximum memory efficiency
        var frameFactory: TexturePackerFrameFactory = new TexturePackerFrameFactory();
        //define an animation by name. That way you can duplication the animations as much as you want efficiently
        frameFactory.define("lazlo", srcBd, frameData);

        //The visual component of the animation
        var container: Sprite = new Sprite();
        var bitmap: Bitmap = new Bitmap();
        container.addChild(bitmap);
        addChild(container);

        //create the animation clip and assign it the name for the animation to show
        var animationClip: FrameFactoryAnimationClip = new FrameFactoryAnimationClip();
        animationClip.setup(bitmap, frameFactory, "lazlo");

        //configure the animation
        var animation: RunnableAnimation = new RunnableAnimation();
        animation.animationClip = animationClip;
        animation.fps = 18; //define the speed unto which to update the frames
        animation.loop = true; //defaults to true
        animation.pingPong = false; //defaults to false
        animation.reverse = false; //defaults to false

        //add it to the scheduler to have it animate
        _taskScheduler.addJob(animation);
    }

    private function onEnterFrame(e: Event): Void {
        //This is the number of milliseconds to spend animating.
        //This is where you can get creative and have tons of animations happening but keeping the frame rate high
        _taskScheduler.runJobs(10);
    }

}

openfl-oasis's People

Contributors

skylerparr avatar

Watchers

 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.