Methods
# clearDialog()
Clears and hides the dialog box.
- Deprecated:
- Yes
Example
// Display some dialog.
rpgcode.showDialog("Hello world!");
// Clears the dialog after 5 seconds have elapsed.
rpgcode.delay(5000, function(){
rpgcode.clearDialog();
});
# delay(ms, callback, loop) → {Object}
Delays the execution of a callback for a specified number of milliseconds,
after which the callback function is invoked.
Parameters:
Name | Type | Description |
---|---|---|
ms |
number | Time to wait in milliseconds. |
callback |
Callback | Function to execute after the delay. |
loop |
boolean | Should the call be indefinite? |
Reference to the delay object.
Object
Example
// Logs to the console after 5 seconds
rpgcode.delay(5000, function(){
rpgcode.log("Hello world!");
});
# getRandom(min, max) → {number}
Gets a random number between the min and max inclusive.
Parameters:
Name | Type | Description |
---|---|---|
min |
number | Minimum value for the random number. |
max |
number | Maximum value for the random number. |
A random number in the from the requested range.
number
Example
var result = rpgcode.getRandom(1, 10);
rpgcode.log(result); // Will be between 1 and 10.
# getScale() → {number}
Gets the current scale factor that the renderer has been drawn with, useful
for creating responsive and scalable UIs.
number
Example
var scale = rpgcode.getScale();
rpgcode.log(scale);
# getViewport() → {Util.Viewport}
Gets the viewport object, this is useful for calculating the position of
characters or sprites on the board relative to the RPGcode screen.
The viewport contains the (x, y) values of the upper left corner of screen
relative to a board's (x, y). It also returns the width and height of the
viewport, and the current visual offset (x, y) of the board and viewport.
Example
var viewport = rpgcode.getViewport();
rpgcode.log(viewport.x);
rpgcode.log(viewport.y);
rpgcode.log(viewport.width);
rpgcode.log(viewport.height);
rpgcode.log(viewport.offsetX);
rpgcode.log(viewport.offsetY);
# hitCharacter(characterId, damage, animationId, callback)
Hits the character dealing the requested damage while playing the corresponding
animation. Optionally a callback can be invoked when the hit animation
has finished playing.
Parameters:
Name | Type | Description |
---|---|---|
characterId |
string | ID of the character. |
damage |
number | Amount of health to take away. |
animationId |
string | Animation to play while the character is hit. |
callback |
Callback | An optional function to invoke when the animation has ended. |
Example
// Without a callback.
rpgcode.hitCharacter("Hero", 1, "DEFEND");
// With a callback.
rpgcode.hitCharacter("Hero", 1, "DEFEND", function() {
// The animation has ended, do something.
});
# hitEnemy(spriteId, damage, animationId, callback)
Hits the enemy dealing the requested damage while playing the corresponding
animation. Optionally a callback can be invoked when the hit animation
has finished playing.
Parameters:
Name | Type | Description |
---|---|---|
spriteId |
string | ID of the BoardSprite that represents the enemy. |
damage |
number | Amount of health to take away. |
animationId |
string | Animation to play while the enemy is hit. |
callback |
Callback | An optional function to invoke when the animation has ended. |
Example
// Without a callback.
rpgcode.hitEnemy("rat-1", 1, "DEFEND");
// With a callback.
rpgcode.hitEnemy("rat-1", 1, "DEFEND", function() {
// The animation has ended, do something.
});
# isControlEnabled() → {boolean}
Returns a true or false value indicating whether standard movement controls
are currently enabled in the engine.
true if the player has control, false otherwise
boolean
Example
var controlEnabled = rpgcode.isControlEnabled();
rpgcode.log(controlEnabled);
# log(message)
Log a message to the console.
Parameters:
Name | Type | Description |
---|---|---|
message |
string | Message to log. |
Example
rpgcode.log("Hello world!");
# restart()
Restarts the game by refreshing the browser page.
Example
rpgcode.restart(); // Will refresh the browser page.
# setDialogDimensions(profileDimensions, dialogDimensions)
Sets the dialog box's profile and text area dimensions.
Parameters:
Name | Type | Description |
---|---|---|
profileDimensions |
Object | Dimensions object containing a width and height. |
dialogDimensions |
Object | Dimensions object containing a width and height. |
- Deprecated:
- Yes
Example
// Set the profile picture to use and the background dialog image.
var profileDimensions = {width: 100, height: 100};
var dialogDimensions = {width: 640, height: 480};
rpgcode.setDialogDimensions(profileDimensions, dialogDimensions);
# setDialogGraphics(profileImage, backgroundImage)
Sets the dialog box's speaker profile image and the background image.
Parameters:
Name | Type | Description |
---|---|---|
profileImage |
string | The relative path to the profile image. |
backgroundImage |
string | The relative path to the background image. |
- Deprecated:
- Yes
Example
// Set the profile picture to use and the background dialog image.
rpgcode.setDialogGraphics("sword_profile_1_small.png", "mwin_small.png");
# setDialogPadding(padding)
Sets the padding from the top left corner of the dialog window for
the x and/or y values. This can be used to prevent text from overlapping
the start or end of the dialog window graphics. The default padding value
is 5px for both x and y.
Parameters:
Name | Type | Description |
---|---|---|
padding |
Object | An object containing x and/or y padding values in pixels. |
- Deprecated:
- Yes
Example
// Set just the x padding value.
rpgcode.setDialogPadding({x: 10});
// Set just the y padding value.
rpgcode.setDialogPadding({y: 10});
// Set both.
rpgcode.setDialogPadding({x: 10, y: 10});
# setDialogPosition(position)
Sets the position of the dialog window for the next call to showDialog.
The dialog window can either appear at the top of the screen i.e. "NORTH", or
the bottom of the screen i.e. "SOUTH". The default position is "SOUTH".
Parameters:
Name | Type | Description |
---|---|---|
position |
string | Either NORTH (top of screen) or SOUTH (bottom of screen). |
- Deprecated:
- Yes
Example
rpgcode.setDialogPosition(rpgcode.dialogPosition.NORTH);
rpgcode.showDialog("Hello north!");
rpgcode.delay(5000, function() {
rpgcode.clearDialog();
rpcode.setDialogPosition(rpgcode.dialogPosition.SOUTH);
rpgcode.showDialog("Hello south!");
});
# showDialog(dialog)
Shows the dialog window and adds the dialog to it if it is already
visible the dialog is just appended to the current window.
Note the dialog window is drawn on the default "renderNowCanvas".
Parameters:
Name | Type | Description |
---|---|---|
dialog |
string | The dialog to output. |
- Deprecated:
- Yes
Example
rpgcode.showDialog("Pssst, Over here");