UNPKG

pxt-common-packages

Version:
83 lines (71 loc) 3.35 kB
# tilemap Location Get the location of a sprite on the tilemap. ```sig sprites.create(null).tilemapLocation() ``` 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. The tile that is under the center of the sprite is considered as the sprite's tilemap **location**. A sprite may overlap multiple tiles but the tile under the sprite's `x` and `y` coordinate properties is its tilemap location. ## Returns * a tile [location](/reference/scene/location) object for the location of the sprite on the tilemap. ## Example #example Make a grid tilemap with two tile colors. Create a sprite to appear on the tilemap. Display the column and row postion of the sprite on the tilemap. ```blocks tiles.setCurrentTilemap(tilemap`level1`) let mySprite = sprites.create(img` . . 4 4 4 . . . . 4 4 4 . . . . . 4 5 5 5 e . . e 5 5 5 4 . . . 4 5 5 5 5 5 e e 5 5 5 5 5 4 . . 4 5 5 4 4 5 5 5 5 4 4 5 5 4 . . e 5 4 4 5 5 5 5 5 5 4 4 5 e . . . e e 5 5 5 5 5 5 5 5 e e . . . . . e 5 f 5 5 5 5 f 5 e . . . . . . f 5 5 5 4 4 5 5 5 f . . f f . . f 4 5 5 f f 5 5 6 f . f 5 f . . . f 6 6 6 6 6 6 4 4 f 5 5 f . . . f 4 5 5 5 5 5 5 4 4 5 f . . . . f 5 5 5 5 5 4 5 5 f f . . . . . f 5 f f f 5 f f 5 f . . . . . . f f . . f f . . f f . . . `, SpriteKind.Player) let tmLocation = mySprite.tilemapLocation() mySprite.sayText("col: " + tmLocation.column + " row: " + tmLocation.row) ``` ## See also #seealso [get tile location](/reference/scene/get-tile-location) ```jres { "transparency16": { "data": "hwQQABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==", "mimeType": "image/x-mkcd-f4", "tilemapTile": true }, "tile1": { "data": "hwQQABAAAADu7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7g==", "mimeType": "image/x-mkcd-f4", "tilemapTile": true, "displayName": "myTile" }, "tile2": { "data": "hwQQABAAAACZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmQ==", "mimeType": "image/x-mkcd-f4", "tilemapTile": true, "displayName": "myTile0" }, "level1": { "id": "level1", "mimeType": "application/mkcd-tilemap", "data": "MTAwYTAwMDgwMDAyMDEwMjAxMDIwMTAyMDEwMjAxMDEwMjAxMDIwMTAyMDEwMjAxMDIwMjAxMDIwMTAyMDEwMjAxMDIwMTAxMDIwMTAyMDEwMjAxMDIwMTAyMDIwMTAyMDEwMjAxMDIwMTAyMDEwMTAyMDEwMjAxMDIwMTAyMDEwMjAyMDEwMjAxMDIwMTAyMDEwMjAxMDEwMjAxMDIwMTAyMDEwMjAxMDIwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMA==", "tileset": [ "myTiles.transparency16", "myTiles.tile1", "myTiles.tile2" ], "displayName": "level1" }, "*": { "mimeType": "image/x-mkcd-f4", "dataEncoding": "base64", "namespace": "myTiles" } } ```