UNPKG

pxt-common-packages

Version:
93 lines (79 loc) 3.47 kB
# get Tile Location Get the tile location object for a particular column and row position in the tilemap. ```sig tiles.getTileLocation(0, 0) ``` A tile location object represents a column and a row position in the tilemap. Location objects are used to get and set tiles or tile information for specific places in the tilemap. ## Parameters * **col**: a [number](/types/number) that is the tilemap column of the tile location. * **row**: a [number](/types/number) that is the tilemap row of the tile location. ## Returns * a tile [location](/reference/scene/location) object for a given column and row in the tilemap. ## Example #example Make a grid tilemap with two tile colors. Create a round shaped sprite. Ramdomly choose a tile location to place the sprite at in the grid. ```blocks tiles.setTilemap(tilemap`level1`) let 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) forever(function () { tiles.placeOnTile(mySprite, tiles.getTileLocation(randint(0, 9), randint(0, 6))) pause(500) }) ``` ## See also #seealso [location](/reference/scene/location), [set tile at](/reference/scene/set-tile-at), [place on tile](/reference/scene/place-on-tile) ```jres { "transparency16": { "data": "hwQQABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==", "mimeType": "image/x-mkcd-f4", "tilemapTile": true }, "tile1": { "data": "hwQQABAAAADd3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3Q==", "mimeType": "image/x-mkcd-f4", "tilemapTile": true, "displayName": "myTile" }, "tile2": { "data": "hwQQABAAAABVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVQ==", "mimeType": "image/x-mkcd-f4", "tilemapTile": true, "displayName": "myTile0" }, "level1": { "id": "level1", "mimeType": "application/mkcd-tilemap", "data": "MTAwYTAwMDgwMDAxMDIwMTAyMDEwMjAxMDIwMTAyMDIwMTAyMDEwMjAxMDIwMTAyMDEwMTAyMDEwMjAxMDIwMTAyMDEwMjAyMDEwMjAxMDIwMTAyMDEwMjAxMDEwMjAxMDIwMTAyMDEwMjAxMDIwMjAxMDIwMTAyMDEwMjAxMDIwMTAxMDIwMTAyMDEwMjAxMDIwMTAyMDIwMTAyMDEwMjAxMDIwMTAyMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMA==", "tileset": [ "myTiles.transparency16", "myTiles.tile1", "myTiles.tile2" ], "displayName": "level1" }, "*": { "mimeType": "image/x-mkcd-f4", "dataEncoding": "base64", "namespace": "myTiles" } } ```