pxt-common-packages
Version:
Microsoft MakeCode (PXT) common packages
47 lines (37 loc) • 1.35 kB
Markdown
Move a sprite to the center of a selected tile.
```sig
tiles.getTileLocation(0, 0).place(null)
```
You a can place a sprite directly on a tile. If you have a [tile](/types/tile) location from the tilemap, just use **place** to put a sprite on top of it.
* **sprite**: the sprite to move onto the tile.
Make a tilemap with several different tiles. Create a circle sprite. Choose the tile at position (1, 1) in the tilemap and place the sprite over it.
```blocks
let mySprite: Sprite = null
// TODO tiles.setTilemap(tiles.createTilemap(null, 0, 8 ** 8, 9));
mySprite = sprites.create(img`
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . 7 7 7 7 7 7 . . . . .
. . . 7 7 7 7 7 7 7 7 7 7 . . .
. . . 7 7 7 7 7 7 7 7 7 7 . . .
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
. . . 7 7 7 7 7 7 7 7 7 7 . . .
. . . 7 7 7 7 7 7 7 7 7 7 . . .
. . . . . 7 7 7 7 7 7 . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
`, SpriteKind.Player)
pause(1000)
let tileDock = tiles.getTileLocation(1, 1)
tileDock.place(mySprite)
```
[](/reference/tiles/get-tile-location)