78 SpawnEntities - JcerelusDev/CanvasGameJs GitHub Wiki

SpawnEntities

Is used to spawn sprite from tiled map editor

new  SpawnEntities(name, id, col, row, sw, sh, type, array, size, health) 

Explanation

name = name of the tile layer

id = any id of your choice

col = starting column from the spriteSheet image

row = starting row from the SpriteSheet image

sw = frameWidth

sh = frameHeight

type = "sheet" (if it's a spriteSheet image) or "single" (if it's a single image)

array = an array of enemies / npcs and so one see example below

size = width and height

health = the health of the sprite

Example

let enemies =[]

 function spawnEnemies(){
setTimeout(function(){
let enemyList = new  SpawnEntities("enemySpawn", "enemy", 4, 6, 51, 71, "sheet", enemies, 24, 10)
    enemyList.asyncOperation();
for (let enemy of enemies) {
   enemy.healthbar = new TinyBar(3, "white", enemy,"steelblue");
}

},1000) // depending on the amount of enemies the timeout may be higher or lower 


}

spawnEnemies()

In a game with multiple levels you may call that function anytime you are loading a new map that has enemySpawn , fir this you may have level switch function to switch from one level to another.