pxt-common-packages
Version:
Microsoft MakeCode (PXT) common packages
75 lines (63 loc) • 2.38 kB
Markdown
# tile Kind At
Check if the type of tile next to the sprite is of a specific kind
```sig
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](/types/image). A boolean is returned.
## Parameters
* **direction**: the direction of the tile, relative to the sprite: ``left``, ``right``, ``top``, ``bottom``, or ``center`` (directly under your sprite).
* **image**: the chosen tile image
## Returns
* a [boolean](/types/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.
```blocks
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
```
## See also #seealso
[is hitting tile](/reference/sprites/sprite/is-hitting-tile),
[on overlap tile](/reference/tiles/on-overlap-tile)
[on hit wall](/reference/tiles/on-hit-wall)