Grape.Sprite Class
A sprite is an image or an animation. It can be defined as a part of a real image (tile sets). When a sprite is an animation, the subsequent images have to be next to each other (left to right direction)
Constructor
Grape.Sprite
-
url
-
opts
Parameters:
-
url
String -
opts
ObjectInitial properties
Item Index
Methods
Methods
getResourceKey
()
An abstract method which should return the same key when the resource is the same, it is used as cache key. A typical key is the url.
loadResource
-
onFinish
-
onError
-
onProgress
This method is called when we want to load the resource and it is not in the cache.
Parameters:
-
onFinish
FunctionShould be called when the resource is ready. The parameter is the loaded data.
-
onError
FunctionShould be called when an error occurs
-
onProgress
FunctionShould be called when the loading progress changes (0-100)
process
-
(*)
This method is called after load is called. If load is called multiple times, this method is not called more than once. It should initialize the resource with the loaded data.
Parameters:
-
(*)
Objectdata The loaded data (passed to the onFinish method in loadResource
Properties
bottomBounding
Number
The bottom side of the sprite's bounding box. If not set it will be the image height.
height
Number
The height of the sprite. If not set, it will be the height of the image.
left
Number
The left position of the sprite in the image.
Default: 0
leftBounding
Number
The left side of the sprite's bounding box
Default: 0
originX
Number
The x coordinate of the sprite origin
Default: 0
originY
Number
The y coordinate of the sprite origin
Default: 0
rightBounding
Number
The right side of the sprite's bounding box. If not set, it will be the image width.
subimages
Number
The number of subimages (animation length). Subsequent images have to be arranged left to right.
Default: 1
top
Number
The top position of the sprite in the image.
Default: 0
topBounding
Number
The top side of the sprite's bounding box
Default: 0
width
Number
The width of the sprite. If not set, it will be calculated by the image width and the animation length.