tile Kind At
Check if the type of tile next to the sprite is of a specific kind
sprites.create(null).tileKindAt(Direction.Center, img``)
You can check to see if the tiles next to or under your sprite have a specific tile image. A boolean is returned.
Parameters
- direction: the direction of the tile, relative to the sprite:
left
,right
,top
,bottom
, orcenter
(directly under your sprite). - image: the chosen tile image
Returns
- a boolean which indicates whether the tile has the specified image.
Example
Build a brick wall of tiles in the scene. Send a arrow sprite towards the wall. When the sprite hits the wall, say what type of tile it contacted.
let mySprite: Sprite = null
let flipImage: Image = null
scene.onHitTile(SpriteKind.Player, 2, function (sprite) {
sprite.say("tile: " + sprite.tileHitFrom(CollisionDirection.Left))
})
scene.setTile(2, img`
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 2 2 2 2 2 2 2 2 2 2 2 2 f 2 1
1 2 2 f 2 2 2 2 2 2 2 2 2 2 2 1
1 2 2 2 2 2 2 f 2 2 2 2 2 2 2 1
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 2 2 2 2 2 2 2 2 2 2 2 f 2 2 1
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 2 2 2 2 f 2 2 2 f 2 2 2 2 2 1
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 2 2 f 2 2 2 2 2 2 2 2 f 2 2 1
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 2 2 2 2 2 2 f 2 2 2 2 f 2 2 1
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
`, true)
// TODO tiles.setTilemap(tiles.createTilemap(null, 0, 8 ** 8, 9));
flipImage = img`
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . 5 5 5 5 5 5 . . . . .
. . . 5 5 5 5 5 5 5 . . . . . .
. . 5 5 5 5 5 5 5 . . . . . . .
. 5 5 5 5 5 5 5 . . . . . . . .
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
. 5 5 5 5 5 5 5 . . . . . . . .
. . 5 5 5 5 5 5 5 . . . . . . .
. . . 5 5 5 5 5 5 5 . . . . . .
. . . . . 5 5 5 5 5 5 . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
`
mySprite = sprites.create(flipImage, SpriteKind.Player)
mySprite.vx = -50