The Official Blog of Patcoola

Im just a dude watching over my parents,
and trying to make cartoons and video games from home.

Script: Simple Sprite Sheet [JS Class]

Important!

Dear visitors,

This blog and the Tigarus.com network will be changing our website software in May (2024). There will be some down time and there will be a change to the webpage addresses.

We will also be removing the Anime blogs. The Rocksmith Songs website will be unavailable of a few weeks or months while I move the database to the new software.

At the moment we are running on Wordpress, the new software is an in-house project which is 57 times faster. It will also provide more freedom for development.

Thank you for understanding.

, By Patcoola

Script Title: simpleSpriteSheet
Programming Language: Java Script
Date Completed: 2012/09/24

Purpose: To display a sprite sheet animation style system for animation and 2D game development. Simple sheet system allows for a horizontal or vertical sprite sheet to be displayed like animation or display a select frame.

Advertisement

Donate Now!

I don't always use the women's bathroom, but when I do, you can bet it really smells. If you like my blog, please consider donating.


Description: Simple sprite sheet style system for animation or displaying a select frame. Allows for a horizontal or vertical sprite sheet to be used. Similar properties and functions to Action Scripting, with play(), gotoAndPlay(), etc.

Compatibility: Works with all Web browsers

Methods:

var class = new simpleSpriteSheet();

Properties
class.img;Set image source of sprite sheet
class.targetId;Set the element ID to assign to
class.horizontal;Default false, Set true if the sprite sheet is horizontal
class.vertical;Default false, Set true if the sprite sheet is vertical
class.height;Set the height in pixels of the sprite area
class.width;Set the width in pixels of the sprite area
class.totalFrames;Set the total number of sprite on the sheet
class.frameRate;Default 60, Set the frame rate when played
class.current;Default 1, Set or return the current frame
class.playOnce;Default false, Set true to play only once

Functions
class.create();Assign and initialize sprite sheet for use
class.play();Play sprite sheet animation
class.pause();Pause sprite sheet animation
class.stop();Stop sprite sheet animation, back to frame one
class.gotoAndStop( int );Go to frame and don’t play animation
class.gotoAndPlay( int );Go to frame and play animation

Example Horizontal Sprite Sheet:

Example Frame 3:

Example Usage:
HTML

<div id=”instance0″></div>

Java Script

instance0 = new simpleSpriteSheet();
instance0.horizontal = true;
instance0.width = 200;
instance0.height = 200;
instance0.current = 1;
instance0.totalFrames = 4;
instance0.frameRate = 4;
instance0.img = “sheet-1.jpg”;
instance0.targetId = “instance0”;
instance0.create();
instance0.play();

 

Advertisement

Donate Now!

Hey buddy, it takes a lot to make a blog. How about a donation?


 

Post Meta

Share Post

 

Comments: Write Comment

Be the first to write a comment.


Leave a Comment


All comments are reviewed before publishing. Comments must be related to the page topic, must not be spam, and must comply with the criminal code of Canada.