Coder Social home page Coder Social logo

jsprite's Introduction

jSprite

Quick and easy JavaScript sprites for use in your html.

USAGE:

  • Set spriteSheet to the src of the sprite sheet image
  • Set container to the ID of the html element that will contain your sprite
  • Set no of columns the sprite sheet has
  • Set no of rows the sprite sheet has
  • If your sprite is not aligned on the x axis correctly you can adjust the x offset viaw "widthOffset: -5"
  • Set the timing of the sprite, note you can control the timings of each frame individually if you use timings and feed it an array of number matching the number of frames in your sprite.



NOTE:
jSprite will resize the container to the dimensions it calculates the a single sprite frame to be, if you wish to adjust size of the sprite you can use transform scale via css or javascript.

let mySprite = new jSprite({
	spriteSheet: "./images/sheet1.png",
	container: "htmlID",
	columns: 8,
	rows: 4,
	widthOffset: 0,
	startFrame: 17,
	length: 8,
	timing: 75,
	autoStart: true,
	repeat: true,
	onComplete: function,
	onProgress: function,
	onComplete: function,
	onRepeat: function,
	onStop: function
});


Parameters

Name Type Info
spriteSheet String REQUIRED The path to the sprite sheet image
container String REQUIRED ID of html element to use for the sprite
columns Number REQUIRED The number of columns your sprite sheet has
rows Number REQUIRED The number of rows your sprite sheet has
timing Number REQUIRED The delay in ms between each frame
widthOffset Number If the sprite is not quite divisible by it's no of columns then you can adjust it with the widthOffset
startFrame Number The number of which frame you would like to start on
length Number The number of frames you would like to play from the start frame (do not exceed max length)
repeat Boolean Do you want the sprite animation to repeat, yes = true, no = false, default = true
onStart function Function callback for when start is called
onStop function Function callback for when stop is called
onProgress function Function called for each frame setp of the sprite
onRepeat function Function callback for when sprite animation repeats
onComplete function Function callback for when sprite animation is complete





Methods

Name Info
start() Starts/resumes the sprite animation
stop() Stops the sprite animation
restart() Restarts the sprite animation from start
setStartFrame(frameNo) Sets the sprite start frame
setLength() Sets the length of the animations aka the no' of frames to play





USAGE DEMOS:

DEMO: https://aftc.io/jSprite/





Licence:

MIT License

Copyright (c) Darcey Lloyd

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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.