Namespace

Asset

Asset

For more information, see Asset Management

View Source rpgcode.js, line 13

Methods

# isAssetLoaded(asset, type) → {boolean}

Returns a true or false value indicating whether an asset is currently loaded. Note: For audio files use the identifier key, not the filename.
Parameters:
Name Type Description
asset string Filename of the asset including any subfolders.
type string Either "image" or "audio".

View Source rpgcode.js, line 1909

boolean
Example
rpgcode.log(rpgcode.isAssetLoaded("Hero/attack_east.png", "image")); // logs true
rpgcode.log(rpgcode.isAssetLoaded("intro", "audio")); // logs true

# loadAssets(assets, onLoad)

Loads the requested assets into the engine, when all of the assets have been loaded the onLoad callback is invoked. For more information, see Asset Management
Parameters:
Name Type Description
assets Asset.Assets Object of assets to load.
onLoad Callback Callback to invoke after assets are loaded.

View Source rpgcode.js, line 1982

Example
// Game assets used in this program.
var assets = {
 "audio": {
     "intro": "intro.mp3"
 },
 "images": [
     "block.png",
     "mwin_small.png",
     "sword_profile_1_small.png",
     "startscreen.png"
 ]
};

// Load up the assets we need
rpgcode.loadAssets(assets, function () {
 // Assets we need are ready, continue on...
});

# removeAssets(assets)

Removes assets from the engine and frees up the memory allocated to them.
Parameters:
Name Type Description
assets Asset.Assets The object containing the assets identifiers.

View Source rpgcode.js, line 2565

Example
// Game assets to unload from the engine.
var assets = {
 "audio": {
     "intro": "intro.mp3"
 },
 "images": [
     "block.png",
     "mwin_small.png",
     "sword_profile_1_small.png",
     "startscreen.png"
 ]
};

// Remove some assets after use
rpgcode.removeAssets(assets); 

Type Definitions

Object

# Assets

Properties:
Name Type Description
images Array.<string>
audio Array.<Asset.KeyValue>
programs Array.<string>

View Source rpgcode.js, line 3629

Object

# BoardAsset

Properties:
Name Type Description
name string
backgroundMusic string
firstRunProgram string
width number
height number
tileWidth number
tileHeight number
tileSets Array.<string>
layers Array.<Asset.BoardLayer>
sprites Array.<Asset.BoardSprite>
startingPosition Geometry.Location

View Source rpgcode.js, line 3923

Example
{
    "backgroundMusic": "Tower.ogg",
    "firstRunProgram": "entry.js",
    "height": 10,
    "layers": [{
            "images": [{
                    "id": "image-1",
                    "src": "background.png",
                    "x": 0,
                    "y": 0
                }
            ],
            "name": "Base",
            "tiles": ["0:11"],
            "vectors": [{
                    "events": [{
                            "key": "E",
                            "program": "auto_generated/1586278226170_d49fe8d2-171c-4b7c-b625-bda20c6eacbb.js",
                            "type": "keypress"
                        }
                    ],
                    "id": "",
                    "isClosed": true,
                    "points": [{
                            "x": 361,
                            "y": 64
                        }
                    ],
                    "type": "PASSABLE"
                }
            ]
        }
    ],
    "name": "demo.board",
    "sprites": [{
            "name": "Torch.npc",
            "id": "b596ab34-903c-4856-9d1d-90f6465c075a",
            "thread": "Idle.js",
            "startingPosition": {
                "x": 112,
                "y": 80,
                "layer": 0
            },
            "events": []
        }
    ],
    "startingPosition": {
        "layer": 0,
        "x": 242,
        "y": 178
    },
    "tileHeight": 32,
    "tileSets": ["tower.tileset"],
    "tileWidth": 32,
    "version": 1.7,
    "width": 15
} 
Object

# BoardLayer

Properties:
Name Type Description
name string
tiles Array.<string>
images Array.<Asset.LayerImage>
vectors Array.<Asset.LayerVector>

View Source rpgcode.js, line 3998

Object

# BoardSprite

Properties:
Name Type Description
name string
id string
thread string
events Array.<Asset.Event>
startingPosition Geometry.Location

View Source rpgcode.js, line 4007

Asset.Sprite

# CharacterAsset

Properties:
Name Type Description
level number
maxLevel number
health number
maxHealth number
attack number
maxAttack number
defence number
maxDefence number
magic number
maxMagic number
experience number
inventory Asset.KeyValue
equipment Asset.KeyValue

View Source rpgcode.js, line 3832

Example
{
    "maxLevel": 10,
    "magic": 0,
    "maxDefence": 0,
    "baseVectorOffset": {
        "x": -15,
        "y": 8
    },
    "defence": 0,
    "graphics": {
        "PROFILE": "sword_profile_1_small.png"
    },
    "experience": 0,
    "inventory": {
        "TODO": "TODO"
    },
    "gold": 0,
    "frameRate": 0,
    "attack": 1,
    "animations": {
        "DEFEND": "Hero/south_hurt.animation"
    },
    "maxHealth": 5,
    "activationOffset": {
        "x": -20,
        "y": 1
    },
    "level": 0,
    "maxMagic": 0,
    "maxAttack": 1,
    "health": 5,
    "equipment": {
        "head": "",
        "accessory-2": "",
        "accessory-1": "",
        "chest": "",
        "gloves": "",
        "right-hand": "",
        "boots": "",
        "left-hand": ""
    },
    "maxExperience": 0,
    "version": 1.7,
    "baseVector": {
        "events": [{
                "program": "",
                "type": "overlap"
            }
        ],
        "points": [{
                "x": 0,
                "y": 0
            }
        ]
    },
    "activationVector": {
        "events": [{
                "program": "",
                "type": "overlap"
            }
        ],
        "points": [{
                "x": 0,
                "y": 0
            }
        ]
    },
    "baseVectorDisabled": false,
    "name": "Hero",
    "activationVectorDisabled": false
}
Asset.Sprite

# EnemyAsset

Properties:
Name Type Description
level number
health number
attack number
defence number
magic number
experienceReward number
goldReward number

View Source rpgcode.js, line 3766

Example
{
    "activationOffset": {
        "x": -20,
        "y": -5
    },
    "activationVector": {
        "events": [{
                "program": "",
                "type": "overlap"
            }
        ],
        "points": [{
                "x": 0,
                "y": 0
            }
        ]
    },
    "activationVectorDisabled": false,
    "animations": {
        "ATTACK": "Evil Eye/attack.animation"
    },
    "attack": 1,
    "baseVector": {
        "events": [{
                "program": "",
                "type": "overlap"
            }
        ],
        "points": [{
                "x": 0,
                "y": 0
            }
        ]
    },
    "baseVectorDisabled": false,
    "baseVectorOffset": {
        "x": -15,
        "y": 0
    },
    "defence": 0,
    "experienceReward": 0,
    "frameRate": 0,
    "goldReward": 0,
    "graphics": {
        "PROFILE": ""
    },
    "health": 5,
    "level": 0,
    "magic": 0,
    "name": "Evil Eye",
    "version": 1.7
}
Object

# Event

Properties:
Name Type Description
program string
type string
key string

View Source rpgcode.js, line 3688

Object

# Item

Properties:
Name Type Description
name string
description string
type string
icon string
price number
effects Asset.ItemEffects
version numbers

View Source rpgcode.js, line 3644

Example
{
    "description": "",
    "effects": {
        "attack": 0,
        "defence": 0,
        "health": 1,
        "magic": 0
    },
    "icon": "Icons/Item__64.png",
    "name": "Apple",
    "price": 0,
    "type": "battle",
    "version": 1.7
}
Object

# ItemEffects

Properties:
Name Type Description
attack number
defence number
health number
magic number

View Source rpgcode.js, line 3672

Object

# KeyValue

Properties:
Name Type Description
key string
value string

View Source rpgcode.js, line 3637

Object

# LayerImage

Properties:
Name Type Description
id string
src string
x number
y number

View Source rpgcode.js, line 4017

Object

# LayerVector

Properties:
Name Type Description
id string
type string
isClosed string
points string
events Array.<Asset.Event>

View Source rpgcode.js, line 4026

Asset.Sprite

# NpcAsset

View Source rpgcode.js, line 3713

Example
{
    "activationOffset": {
        "x": -5,
        "y": -5
    },
    "activationVector": {
        "events": [{
                "program": "",
                "type": "overlap"
            }
        ],
        "points": [{
                "x": 0,
                "y": 0
            }
        ]
    },
    "activationVectorDisabled": false,
    "animations": {
        "ATTACK": ""
    },
    "baseVector": {
        "events": [{
                "program": "",
                "type": "overlap"
            }
        ],
        "points": [{
                "x": 0,
                "y": 0
            }
        ]
    },
    "baseVectorDisabled": false,
    "baseVectorOffset": {
        "x": -5,
        "y": -5
    },
    "description": "Undefined",
    "frameRate": 0,
    "graphics": {
        "PROFILE": ""
    },
    "name": "Untitled",
    "version": 1.7
}
Object

# Sprite

Properties:
Name Type Description
name string
description string
activationVector Asset.Vector
activationOffset Geometry.Point
activationVectorDisabled boolean
animations Asset.KeyValue
baseVector Asset.Vector
baseVectorOffset Geometry.Point
baseVectorDisabled boolean
frameRate number
graphics Asset.KeyValue
version string

View Source rpgcode.js, line 3696

Object

# Vector

Properties:
Name Type Description
events Array.<Asset.Event>
points Array.<Geometry.Point>

View Source rpgcode.js, line 3681