UNPKG

pxt-common-packages

Version:
82 lines (70 loc) 2.35 kB
# tile Hit From Find out what type of tile the sprite has hit. ```sig sprites.create(null).tileHitFrom(CollisionDirection.Left) ``` If your sprite is contacting a wall tile, you can find out what kind of tile it is. The tile index in the tile map is returned. ## Parameters * **direction**: the direction check for a wall collision: ``left``, ``right``, ``top``, or ``bottom``. ## Returns * a [number](/types/number) which is the tile index for the wall tile contacting the sprite. ## 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) scene.setTileMap(img` . . . . . . . . . . . 2 . . . . . . . . . 2 . . . . . . . . . 2 . . . . . . . . . 2 . . . . . . . . . 2 . . . . . . . . . 2 . . . . . . . . . . . . . . . . . . `) 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 wall](/reference/sprites/sprite/is-hitting-wall), [on hit tile](/reference/sprites/on-hit-tile)