get Tiles By Type
Return an array of tile locations from the tilemap that contain the specified tile.
tiles.getTilesByType(null)
Parameters
- tile: a tile image to search the tilemap for.
Returns
- an array of tile locations from the tilemap that have the tile specified in tile.
Example
Make a column of tiles from top to bottom of the screen. Set a sprite in motion and set it to bounce on walls. Every 5
seconds, find the column tiles in the tilemap and set them as either wall tiles or regular tiles.
let isWall = false
tiles.setTilemap(tilemap`level1`)
let mySprite = sprites.create(img`
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . 1 1 1 1 1 1 . . . . .
. . . 1 1 2 2 2 2 2 2 1 1 . . .
. . . 1 2 2 2 2 2 2 2 2 1 . . .
. . 1 2 2 2 2 2 2 2 2 2 2 1 . .
. . 1 2 2 2 2 2 2 2 2 2 2 1 . .
. . 1 2 2 2 2 2 2 2 2 2 2 1 . .
. . 1 2 2 2 2 2 2 2 2 2 2 1 . .
. . 1 2 2 2 2 2 2 2 2 2 2 1 . .
. . 1 2 2 2 2 2 2 2 2 2 2 1 . .
. . . 1 2 2 2 2 2 2 2 2 1 . . .
. . . 1 1 2 2 2 2 2 2 1 1 . . .
. . . . . 1 1 1 1 1 1 . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
`, SpriteKind.Player)
mySprite.setBounceOnWall(true)
mySprite.vx = 80
mySprite.vy = 70
game.onUpdateInterval(5000, function () {
isWall = !(isWall)
for (let wallTile of tiles.getTilesByType(assets.tile`myTile`)) {
tiles.setWallAt(wallTile, isWall)
}
})
See also
{
"transparency16": {
"data": "hwQQABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
"mimeType": "image/x-mkcd-f4",
"tilemapTile": true
},
"tile1": {
"data": "hwQQABAAAADu7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7g==",
"mimeType": "image/x-mkcd-f4",
"tilemapTile": true,
"displayName": "myTile"
},
"level1": {
"id": "level1",
"mimeType": "application/mkcd-tilemap",
"data": "MTAwYTAwMDgwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAxMDAwMDAwMDAwMDAwMDAwMDAxMDAwMDAwMDAwMDAwMDAwMDAwMDAwMTAwMDAwMDAwMDAwMDAwMDAwMTAwMDAwMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAxMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMA==",
"tileset": [
"myTiles.transparency16",
"myTiles.tile1"
],
"displayName": "level1"
},
"*": {
"mimeType": "image/x-mkcd-f4",
"dataEncoding": "base64",
"namespace": "myTiles"
}
}