Methods
# animateCharacter(characterId, animationId, callback)
Animates the character using the requested animation. The animationId must be
available for the character.
Parameters:
Name | Type | Description |
---|---|---|
characterId |
string | The label associated with the character. |
animationId |
string | The requested animation to character for the character. |
callback |
Callback | If defined, the function to invoke at the end of the animation. |
Example
// Without a callback.
rpgcode.animateCharacter("Hero", "HURT_SOUTH");
// With a callback.
rpgcode.animateCharacter("Hero", "HURT_SOUTH", function(){
rpgcode.log("Animated Hero!");
});
# changeCharacterGraphics(characterId, swaps)
Changes a characters visible graphics at runtime by swapping the values stored
in the left-hand slots with those on the right. These keys can be reversed
to restore the previous values.
Parameters:
Name | Type | Description |
---|---|---|
characterId |
string | The label associated with the character. |
swaps |
Object | An object containing the graphics to swap. |
Example
var changes = {
"NORTH": "BOAT_NORTH",
"SOUTH": "BOAT_SOUTH",
"EAST": "BOAT_EAST",
"WEST": "BOAT_WEST",
"NORTH_EAST": "BOAT_NORTH_EAST",
"NORTH_WEST": "BOAT_NORTH_WEST",
"SOUTH_EAST": "BOAT_SOUTH_EAST",
"SOUTH_WEST": "BOAT_SOUTH_WEST"
};
rpgcode.changeCharacterGraphics("Hero", changes);
// To restore the defaults all we need to do is swap them around again.
var changes = {
"BOAT_NORTH": "NORTH",
"BOAT_SOUTH": "SOUTH",
"BOAT_EAST": "EAST",
"BOAT_WEST": "WEST",
"BOAT_NORTH_EAST": "NORTH_EAST",
"BOAT_NORTH_WEST": "NORTH_WEST",
"BOAT_SOUTH_EAST": "SOUTH_EAST",
"BOAT_SOUTH_WEST": "SOUTH_WEST"
};
rpgcode.changeCharacterGraphics("Hero", changes);
# getCharacter() → {Asset.CharacterAsset}
Gets the active character object.
Active character.
Example
var character = rpgcode.getCharacter();
rpgcode.log(character);
# getCharacterDirection() → {"NORTH"|"SOUTH"|"EAST"|"WEST"|"NORTH_EAST"|"SOUTH_EAST"|"NORTH_WEST"|"SOUTH_WEST"}
Gets the character's current direction.
"NORTH"
|
"SOUTH"
|
"EAST"
|
"WEST"
|
"NORTH_EAST"
|
"SOUTH_EAST"
|
"NORTH_WEST"
|
"SOUTH_WEST"
Example
var direction = rpgcode.getCharacterDirection();
rpgcode.log(direction);
# getCharacterLocation(inTiles, includeOffset) → {Geometry.Location}
Gets the character's current location, optionally including the visual offset
that happens when boards are smaller than the viewport dimensions.
Parameters:
Name | Type | Description |
---|---|---|
inTiles |
boolean | Should the location be in tiles, otherwise pixels. |
includeOffset |
boolean | Should the location include the visual board offset. |
An object containing the characters location.
Example
var location = rpgcode.getCharacterLocation();
rpgcode.log(location.x);
rpgcode.log(location.y);
rpgcode.log(location.layer);
# moveCharacter(characterId, direction, distance)
Moves the character by n pixels in the given direction.
Parameters:
Name | Type | Description |
---|---|---|
characterId |
string | The id of the character to move. (unused) |
direction |
string | The direction to push the character in. |
distance |
number | Number of pixels to move. |
Example
// Move the character with the "Hero" ID north 50 pixels.
rpgcode.moveCharacter("Hero", "NORTH", 50);
# moveCharacterTo(characterId, x, y, duration, callback)
Moves the character to the (x, y) position, the character will travel for the
supplied duration (milliseconds).
A short duration will result in the character arriving quicker and vice versa.
Parameters:
Name | Type | Description |
---|---|---|
characterId |
string | The name set for the character as it appears in the editor. |
x |
number | A pixel coordinate on the board. |
y |
number | A pixel coordinate on the board. |
duration |
number | Time taken for the movement to complete (milliseconds). |
callback |
Callback | Function to invoke when the sprite has finished moving. |
Example
// Move towards (100, 150) for 50 milliseconds, this will animate the character.
var characterId = "hero";
var x = 100;
var y = 150;
var delay = 50;
rpgcode.moveCharacterTo(characterId, x, y, delay, function() {
rpgcode.log("character has finished moving");
});
# pauseCharacter()
Pauses animation and movement for the charcter.
Example
// Pauses the character
rpgcode.pauseCharacter();
# resetActivationChecks(characterId)
Resets activation checks for the requested character, useful for cases where
you want to continually check a program activation, e.g. block pushing.
Parameters:
Name | Type | Description |
---|---|---|
characterId |
string | The identifier associated with the character. |
Example
// An example of a pushable block that can only be moved when the character is
// facing EAST. This program would be attached to an NPCs EventProgram.
var direction = rpgcode.getCharacterDirection();
if (!rpgcode.getGlobal("dungeonState").room2.doorOpened && direction === "EAST") {
var id = "pushable-rock";
var movementTime = 500;
var animationId = "SOUTH";
var loc = rpgcode.getSpriteLocation("pushable-rock");
loc.x += 16;
rpgcode.moveSpriteTo("pushable-rock", loc.x, loc.y, movementTime, function() {
rpgcode.playSound("door");
rpgcode.destroySprite("closed_door");
rpgcode.getGlobal("dungeonState").room2.doorOpened=true;
rpgcode.endProgram();
});
} else {
if (!rpgcode.getGlobal("dungeonState").room2.doorOpened) {
rpgcode.resetActivationChecks("Hero");
}
rpgcode.endProgram();
}
# resumeCharacter()
Resumes animation and movement for the charcter.
Example
// Resumes the character
rpgcode.resumeCharacter();
# setCharacterLocation(characterId, x, y, layer, isTiles)
Sets the character's location without triggering any animation.
Parameters:
Name | Type | Description |
---|---|---|
characterId |
string | The identifier associated with character to move. |
x |
number | In pixels by default. |
y |
number | In pixels by default. |
layer |
number | Target layer to put the character on. |
isTiles |
boolean | Is (x, y) in tile coordinates, defaults to pixels. |
Example
var characterId = "Hero";
var x = 10;
var y = 10;
var layer = 1;
var isTiles = true;
rpgcode.setCharacterLocation(characterId, x, y, layer, isTiles);
# setCharacterSpeed(characterId, change)
Sets the character speed by proportionally applying the change, can be used
to increase or decrease the character speed by some factor
i.e. 3 times faster or 3 times slower. Positive change values are interpreted
as an increase and negative values as a decrease.
Parameters:
Name | Type | Description |
---|---|---|
characterId |
string | The index of the character on the board. |
change |
string | Factor to change the character speed by. |
Example
// Increase the character's movement speed by 3 times.
rpgcode.setCharacterSpeed("Hero", 3);
// Decrease the character's movement speed by 3 times, returning it to normal.
rpgcode.setCharacterSpeed("Hero", -3);
# setCharacterStance(characterId, stanceId)
Sets the character's current stance, uses the first frame in the animation.
Parameters:
Name | Type | Description |
---|---|---|
characterId |
string | The index of the character on the board. |
stanceId |
string | The stanceId (animationId) to use. |
Example
// Set the sprite with ID 5 to its idle stance.
var characterId = "Hero";
var stanceId = "IDLE";
rpgcode.setCharacterStance(characterId, stanceId);