Giter VIP home page Giter VIP logo

spriteanimjs's Introduction

SpriteAnimJS

Run spritesheet animations in webGL, that is all.

######Demos here

If you have a DOM app and want to create some fast spritesheets in WebGL, which fall back nicely to Canvas, then this might be of help. Take note that this runs spritesheets standalone, each on its own canvas.

Note

Chrome limits WebGL context instances to 16, so you can run only 16 spritesheets at the same time. Always destroy unused instances.

If you need more than 16 spritesheet animations on your page at the same time, then you might want to consider going full canvas and use a proper javascript game engine :)

#Usage

Create the html canvas element <canvas id="canvas"></canvas>

Initiate SpriteAnim on the canvas element: var mySpriteAnimation = new SpriteAnim(canvasId,forceCanvas2D)

@Param1: {string} - ID of the canvas element

@Param2: {boolean | optional} - Wether to force the spritesheet's render in 2D Canvas or not

Run spritesheet animation

mySpriteAnimation.start({

			frameWidth: 100,
			frameHeight: 100,
			image: image_element, // must be preloaded
			fps: 10,
			className: 'class_name',
			loop: true,
			onStart: function() {},
			onComplete: function() {}
		});

@Prop1: {integer} - Single frame width

@Prop2: {integer} - Single frame height

@Prop3: {element} - Image element of spritesheet, must be preloaded

@Prop4: {integer} - Number of frames per second to run the spritesheet, defaults to 30

@Prop5: {string} || false - Class name(s) which to add on the canvas

@Prop6: {boolean} || false - Whether to loop the animation

@Prop7: {function} || false - Callback function that runs once when the animation starts

@Prop8: {function} || false - Callback function that runs everytime the animation ends

#Methods ####Start instance.start({props})

####Stop instance.stop()

i.e. mySpriteAnimation.stop()

#Preloading

You must preload all of the spritesheets that you are going to use.

--

There you have it, a very easy way to create Sprite Animations in WebGL with fallback to canvas. I use it to create smooth particle-based sprite animations in various places in a webpage or in a game.

spriteanimjs's People

Contributors

catalinberta avatar

Watchers

James Cloos avatar  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.