Skip to content

DarceyLloyd/jSprite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

JavaScript sprite library.

Resources

License

Stars

Watchers

Forks

Packages

No packages published