Methods
# addLayerImage(image, layer)
Adds the layer image to the requested layer, it will be rendered immediately
after being added to the board.
Note: Layers images added this way will be lost the moment the board is reloaded.
Parameters:
Name | Type | Description |
---|---|---|
image |
Object | The layer image to add to the board. |
layer |
number | Layer index on the board, first layer starts at 0. |
Example
var image = {
"src": "battle-background.png", // pre-loaded asset image
"x": 50, // x location on board in pixels
"y": 100, // y location on board in pixels
"id": "battle.background" // unique for this layer image
}
rpgcode.addLayerImage(image, 1); // Adds the image to layer 1 on the current board
# drawImage(fileName, x, y, width, height, rotation, canvasIdopt)
Draws an image onto a canvas, if no canvas is specified the default canvas will be used.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fileName |
string | The relative path to the image. | ||
x |
number | The start position x in pixels. | ||
y |
number | The start position y in pixels. | ||
width |
number | In pixels. | ||
height |
number | In pixels. | ||
rotation |
number | In radians. | ||
canvasId |
string |
<optional> |
renderNowCanvas | The ID of the canvas to put the image on. |
Example
// Draw the image onto the default canvas.
rpgcode.drawImage("life.png", 0, 0, 32, 32, 0);
// Draw the image onto the canvas we specified.
rpgcode.drawImage("life.png", 0, 0, 32, 32, 0, "myCanvas");
# drawImagePart(fileName, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, rotation, canvasIdopt)
Draws part of image an onto a canvas, if no canvas is specified the default canvas will be used.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fileName |
string | The relative path to the image. | ||
srcX |
number | The start position x in pixels from the source image. | ||
srcY |
number | The start position y in pixels from the source image. | ||
srcWidth |
number | In pixels from the source image. | ||
srcHeight |
number | In pixels from the source image. | ||
destX |
number | The start position x in pixels on the destination canvas. | ||
destY |
number | The start position y in pixels on the destination canvas. | ||
destWidth |
number | In pixels on the destination canvas. | ||
destHeight |
number | In pixels on the destination canvas. | ||
rotation |
number | In radians. | ||
canvasId |
string |
<optional> |
renderNowCanvas | The ID of the canvas to put the image on. |
Example
// Draw part of the image onto the default canvas.
rpgcode.drawImagePart("objects.png", 64, 0, 16, 16, 8, 8, 16, 16, 0);
// Draw part of the image onto the canvas we specified.
rpgcode.drawImagePart("objects.png", 64, 0, 16, 16, 8, 8, 16, 16, 0, "myCanvas");
# getImage(fileName) → {Image.ImageInfo}
Gets the image object if it has been loaded into the engine already, otherwise
it returns undefined.
Parameters:
Name | Type | Description |
---|---|---|
fileName |
string | The relative path to the image. |
An object containing information about the image.
Example
// Set the image on the smaller canvas.
var image = rpgcode.getImage("life.png");
rpgcode.log(image.width);
rpgcode.log(image.height);
# removeLayerImage(id, layer)
Removes the layer image with the ID on the specified layer. If the image does
not exist on the layer then there is no effect.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | Unique ID of the layer image to remove. |
layer |
number | Layer index on the board, first layer starts at 0. |
Example
rpgcode.removeLayerImage("battle.background", 1); // Remove the image with ID "battle.background" on layer 1
# setImage()
- Deprecated:
- since 1.7.0, use "drawImage" instead.
# setImagePart()
- Deprecated:
- since 1.7.0, use "drawImagePart" instead.
# updateLayerImage(image, layer)
Update the layer image with the ID on the specified layer. If the image does
not exist on the layer then there is no effect.
Parameters:
Name | Type | Description |
---|---|---|
image |
Object | The layer image to update on the board. |
layer |
number | Layer index on the board, first layer starts at 0. |
Example
var image = {
"src": "battle-background.png", // pre-loaded asset image
"x": 150, // x location on board in pixels
"y": 100, // y location on board in pixels
"id": "battle.background" // unique for this layer image
};
rpgcode.updateLayerImage(image, 1); // Update the image with ID "battle.background" on layer 1