Class Index | File Index

Classes


Class Sprite

A sprite class with different image/animation sequences based upon defined 'actions'.
Defined in: sprite.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Sprite(anchor, frames, loadedcallback, scale)
Allows you to associate a set of animations with a particular entity.
Method Summary
Method Attributes Method Name and Description
 
aabb(pos)
Returns the axis aligned bounding box of this sprite at its current frame.
 
action(a, reset, callback)
Sets which named animation/action to play.
 
angle(a)
Set the angle the sprite to should drawn at (in radians).
 
draw(c, pos)
Draw the sprite.
 
Returns the current action being played.
 
Returns the current frame number being played.
 
Returns the total number of frames.
 
Gets the current size of the current frame, scaled appropriately.
<static>  
Sprite.preload(images, completedcallback, progresscallback)
Pre-loads a whole array of images.
 
set_frame(newframe)
Sets the animation frame to play *
 
Call this method from inside the owner entity's update() method.
Class Detail
Sprite(anchor, frames, loadedcallback, scale)
Allows you to associate a set of animations with a particular entity. To do vector graphics, use the canvas tag methods instead.
Parameters:
anchor
selects which side of the sprite's rectangle to 'anchor' the animation to. e.g. ["center", "bottom"] will anchor the sprite to the ground (side view) whilst ["right", "center"] would anchor it to the right hand side.
frames
is a dictionary containing all actions and their associated set of images and the number of frames to show each image for. For instance: {"stand": [["img/stand.png", 0],], "walk": [["img/walk1.png", 3], ["img/walk2.png", 3],]} where each walk frame is shown for three frames.
loadedcallback
is a function that is called once all of the frames in all action animations are successfully loaded.
scale
is a floating point number that will scale the sprite in size.
Method Detail
aabb(pos)
Returns the axis aligned bounding box of this sprite at its current frame.
Parameters:
pos
is the position to get the aabb relative to (factors the anchor point in too).

action(a, reset, callback)
Sets which named animation/action to play.
Parameters:
a
is the name of the animation/action you defined on initialisation.
reset
indicates whether the frame number should be reset to the start of the animation.
callback
is called when the animation has completed one loop - receives parameter "action".

angle(a)
Set the angle the sprite to should drawn at (in radians). *
Parameters:
a

draw(c, pos)
Draw the sprite. Call this method from inside the owner entity's draw() method.
Parameters:
c
is the canvas to draw on (passed to the entity's draw(c) method)
pos
is the position to draw at relative to the anchor point.

get_action()
Returns the current action being played. *

get_frame()
Returns the current frame number being played. *

get_num_frames()
Returns the total number of frames. *

get_size()
Gets the current size of the current frame, scaled appropriately. *

<static> Sprite.preload(images, completedcallback, progresscallback)
Pre-loads a whole array of images. Provides feedback on which images are loaded via the progresscallback, which returns the number of images left to load each time one is loaded, and 0 when the final image is loaded.
Parameters:
images
is an array of strings containing the URLs of images to load.
completedcallback
is a function which is called when all images are loaded
progresscallback
is a function accepting an integer, which is the count of images left to load

set_frame(newframe)
Sets the animation frame to play *
Parameters:
newframe

update()
Call this method from inside the owner entity's update() method.

Documentation generated by JsDoc Toolkit 2.4.0 on Fri Nov 09 2012 21:19:32 GMT+0800 (WST)