Constructor
new Sprite(game, xopt, yopt, keyopt, frameopt)
Sprites are game objects which contain the actual HTML elements for rendering.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
game |
Carrot.Game | The core game object. | ||
x |
integer |
<optional> |
0 | The x coordinate in the world of the sprite. |
y |
integer |
<optional> |
0 | The y coordinate in the world of the sprite. |
key |
string |
<optional> |
null | This is the image for the sprite. If left empty, the sprite will be just a green rectangle. |
frame |
integer |
<optional> |
0 | Only for spritesheets: The starting frame of the image. If not passed, it will be 0, the first frame. |
Methods
addChild(entity)
Adds a child to the sprite. The entity must be another sprite.
Parameters:
Name | Type | Description |
---|---|---|
entity |
Carrot.Sprite | The entity to add. |
createNode() → {object}
Creates the HTML element for this sprite. Called by {Carrot.Sprite} or revive().
Returns:
- Type
- object
destroy(destroyChildrenopt)
Destroys the sprite and removes it from its group and the game world.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
destroyChildren |
boolean |
<optional> |
false | If true, all the children of the sprite and their children are destroyed, too. |
destroyNode()
Removes the HTML element of this sprite. Called by {Carrot.Sprite}, kill or destroy.
kill(destroyNodeopt)
Kills the sprite. Used for object pools.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
destroyNode |
boolean |
<optional> |
If `true`, will destroy the sprite's HTML element. |
removeChild(entity)
Removes the passed child from the sprite.
Parameters:
Name | Type | Description |
---|---|---|
entity |
Carrot.Sprite | The entity to remove. |
revive()
Revives the sprite. Used for object pools.
setFrame(frameopt)
Changes the frame shown. Only for spritesheets.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
frame |
integer |
<optional> |
0 |
setGlow(bluropt, spreadopt, coloropt, insetopt)
Applies a glow effect on the sprite. Its shape is determined by the sprite's body which can be a rectangle or a circle.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
blur |
integer |
<optional> |
0 | Blur in pixels. |
spread |
integer |
<optional> |
0 | Spread in pixels. |
color |
Carrot.Color | string |
<optional> |
Carrot.Color.Lime | The color of the glow. Must be given in one of the following formats: Hexadecimal, RGB, RGBA, HSL, HSLA or one of the 140 predefined browser colors. |
inset |
boolean |
<optional> |
false | Defines if the glow should be go out or inside the sprite. |