pxt-common-packages 9.5.4 → 9.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/built/common-sim.d.ts +40 -0
- package/built/common-sim.js +93 -1
- package/libs/azureiot/built/debug/binary.js +461 -461
- package/libs/base/sim/core.ts +1 -1
- package/libs/color/built/debug/binary.js +8 -8
- package/libs/color-sensor/built/debug/binary.js +8 -8
- package/libs/controller/built/debug/binary.js +6864 -6864
- package/libs/controller---none/built/debug/binary.js +6844 -6844
- package/libs/datalogger/built/debug/binary.js +63 -63
- package/libs/edge-connector/built/debug/binary.js +8 -8
- package/libs/esp32/built/debug/binary.js +462 -462
- package/libs/game/_locales/game-strings.json +1 -0
- package/libs/game/built/debug/binary.js +6784 -6784
- package/libs/game/docs/reference/sprites/sprite/follow.md +66 -0
- package/libs/game/docs/reference/sprites/sprite/set-bounce-on-wall.md +2 -2
- package/libs/game/docs/reference/sprites/sprite-kind.md +70 -0
- package/libs/game/docs/reference/tiles/get-neighboring-location.md +123 -0
- package/libs/game/docs/reference/tiles/get-tile-location.md +71 -30
- package/libs/game/docs/reference/tiles/get-tiles-by-type.md +66 -32
- package/libs/game/docs/reference/tiles/location.md +246 -0
- package/libs/game/docs/reference/tiles/place-on-random-tile.md +54 -21
- package/libs/game/docs/reference/tiles/place-on-tile.md +88 -0
- package/libs/game/docs/reference/tiles/set-current-tilemap.md +90 -0
- package/libs/game/docs/reference/tiles/set-tile-at.md +47 -30
- package/libs/game/docs/reference/tiles/set-tilemap.md +90 -0
- package/libs/game/docs/reference/tiles/set-wall-at.md +67 -68
- package/libs/game/docs/reference/tiles/tile-at-location-equals.md +97 -0
- package/libs/game/docs/reference/tiles/tile-at-location-is-wall.md +98 -0
- package/libs/game/docs/reference/tiles/tilemap.md +145 -0
- package/libs/game/multiplayer.cpp +25 -0
- package/libs/game/multiplayer.ts +24 -0
- package/libs/game/pxt.json +3 -1
- package/libs/game/scene.ts +1 -0
- package/libs/game/sim/multiplayer.ts +132 -0
- package/libs/game/sprite.ts +2 -1
- package/libs/game/spritekind.ts +1 -0
- package/libs/game/tilemap.ts +12 -11
- package/libs/lcd/built/debug/binary.js +8 -8
- package/libs/light-spectrum-sensor/built/debug/binary.js +8 -8
- package/libs/lora/built/debug/binary.js +8 -8
- package/libs/matrix-keypad/built/debug/binary.js +8 -8
- package/libs/mqtt/built/debug/binary.js +176 -176
- package/libs/net/built/debug/binary.js +176 -176
- package/libs/net-game/built/debug/binary.js +8372 -8372
- package/libs/palette/built/debug/binary.js +6782 -6782
- package/libs/pixel/built/debug/binary.js +8 -8
- package/libs/power/built/debug/binary.js +8 -8
- package/libs/proximity/built/debug/binary.js +8 -8
- package/libs/radio/_locales/radio-strings.json +4 -1
- package/libs/radio/built/debug/binary.js +8 -8
- package/libs/radio/radio.cpp +1 -0
- package/libs/radio/radio.ts +13 -2
- package/libs/radio/shims.d.ts +2 -1
- package/libs/radio-broadcast/_locales/radio-broadcast-strings.json +2 -1
- package/libs/radio-broadcast/built/debug/binary.js +8 -8
- package/libs/radio-broadcast/radio-broadcast.ts +2 -0
- package/libs/rotary-encoder/built/debug/binary.js +8 -8
- package/libs/screen/built/debug/binary.js +50 -50
- package/libs/servo/built/debug/binary.js +8 -8
- package/libs/sprite-scaling/built/debug/binary.js +6782 -6782
- package/libs/storyboard/built/debug/binary.js +6782 -6782
- package/package.json +2 -2
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# follow
|
|
2
|
+
|
|
3
|
+
Set a sprite to always move to the position of another target sprite.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
sprites.create(null).follow(null, 0)
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
When you set a sprite to follow a target sprite, it will move toward the target by "chasing" it with a certain speed. If the sprite can reach the target before it moves again, the sprite will stop and occupy the same location as the target sprite. When not moving, the sprites overlap each other at their center locations.
|
|
10
|
+
|
|
11
|
+
## Parameters
|
|
12
|
+
|
|
13
|
+
* **target**: the target [sprite](/types/sprite) to follow.
|
|
14
|
+
* **speed**: the maximum chase speed after accelerating, in pixels per second, when moving toward the target sprite.
|
|
15
|
+
* **turnRate**: (optional) the time to take in making a turn to toward the target sprite. For example, using the default rate, `400`, the sprite will reach **speed** in 125 milleseconds when turing 180 degrees to chase the target.
|
|
16
|
+
|
|
17
|
+
## Example
|
|
18
|
+
|
|
19
|
+
Create 2 sprites. Set the second sprite to follow the first one. Every second, randomly change the position of the first sprite on the screen so that the second sprite will keep chasing it.
|
|
20
|
+
|
|
21
|
+
```blocks
|
|
22
|
+
let mySprite = sprites.create(img`
|
|
23
|
+
. . . . . . . . . . . . . . . .
|
|
24
|
+
. . . . . . . . . . . . . . . .
|
|
25
|
+
. . . . . 7 7 7 7 7 7 . . . . .
|
|
26
|
+
. . . 7 7 7 7 7 7 7 7 7 7 . . .
|
|
27
|
+
. . . 7 7 7 7 7 7 7 7 7 7 . . .
|
|
28
|
+
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
|
|
29
|
+
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
|
|
30
|
+
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
|
|
31
|
+
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
|
|
32
|
+
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
|
|
33
|
+
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
|
|
34
|
+
. . . 7 7 7 7 7 7 7 7 7 7 . . .
|
|
35
|
+
. . . 7 7 7 7 7 7 7 7 7 7 . . .
|
|
36
|
+
. . . . . 7 7 7 7 7 7 . . . . .
|
|
37
|
+
. . . . . . . . . . . . . . . .
|
|
38
|
+
. . . . . . . . . . . . . . . .
|
|
39
|
+
`, SpriteKind.Player)
|
|
40
|
+
let mySprite2 = sprites.create(img`
|
|
41
|
+
. . . . . . . . . . . . . . . .
|
|
42
|
+
. . . . . . . . . . . . . . . .
|
|
43
|
+
. . . . . 5 5 5 5 5 5 . . . . .
|
|
44
|
+
. . . 5 5 5 5 5 5 5 5 5 5 . . .
|
|
45
|
+
. . . 5 5 5 5 5 5 5 5 5 5 . . .
|
|
46
|
+
. . 5 5 5 5 5 5 5 5 5 5 5 5 . .
|
|
47
|
+
. . 5 5 5 5 5 5 5 5 5 5 5 5 . .
|
|
48
|
+
. . 5 5 5 5 5 5 5 5 5 5 5 5 . .
|
|
49
|
+
. . 5 5 5 5 5 5 5 5 5 5 5 5 . .
|
|
50
|
+
. . 5 5 5 5 5 5 5 5 5 5 5 5 . .
|
|
51
|
+
. . 5 5 5 5 5 5 5 5 5 5 5 5 . .
|
|
52
|
+
. . . 5 5 5 5 5 5 5 5 5 5 . . .
|
|
53
|
+
. . . 5 5 5 5 5 5 5 5 5 5 . . .
|
|
54
|
+
. . . . . 5 5 5 5 5 5 . . . . .
|
|
55
|
+
. . . . . . . . . . . . . . . .
|
|
56
|
+
. . . . . . . . . . . . . . . .
|
|
57
|
+
`, SpriteKind.Player)
|
|
58
|
+
mySprite2.follow(mySprite, 50,)
|
|
59
|
+
game.onUpdateInterval(1000, function () {
|
|
60
|
+
mySprite.setPosition(randint(0, scene.screenWidth()), randint(0, scene.screenHeight()))
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## See also
|
|
65
|
+
|
|
66
|
+
[overlaps with](/reference/sprites/sprite/overlaps-with)
|
|
@@ -43,7 +43,7 @@ mySprite.vx = 50
|
|
|
43
43
|
mySprite.vy = 50
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
###
|
|
46
|
+
### Bounce on the the edge of the screen
|
|
47
47
|
|
|
48
48
|
With a scene that has no tilemap set, make a sprite bounce on the edges of the screen.
|
|
49
49
|
|
|
@@ -97,4 +97,4 @@ mySprite.vy = 50
|
|
|
97
97
|
|
|
98
98
|
## See also
|
|
99
99
|
|
|
100
|
-
[set flag](/reference/sprites/sprite/set-flag), [set stay in screen](/reference/sprites/sprite/set-stay-in-screen)
|
|
100
|
+
[set flag](/reference/sprites/sprite/set-flag), [set stay in screen](/reference/sprites/sprite/set-stay-in-screen)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# sprite Kind
|
|
2
|
+
|
|
3
|
+
Get a sprite kind object from a sprite kind identifier.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
sprites._spriteKind(0)
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
To keep track of different types of sprites, a _kind_ is assigned to them. This is a value that will help identify them and decide what actions to take when events happen in the game. The sprite kinds in your game might be defined like this:
|
|
10
|
+
|
|
11
|
+
```typescript-ignore
|
|
12
|
+
namespace SpriteKind {
|
|
13
|
+
export const Player = SpriteKind.create()
|
|
14
|
+
export const Enemy = SpriteKind.create()
|
|
15
|
+
export const Food = SpriteKind.create()
|
|
16
|
+
...
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
In blocks, a sprite kind identifier is used to make a sprite kind item that can be assigned to a variable or used as a parameter:
|
|
21
|
+
|
|
22
|
+
```block
|
|
23
|
+
let enemyKind = SpriteKind.Enemy
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Parameters
|
|
27
|
+
|
|
28
|
+
* **kind**: the sprite kind identifier to get the kind object for.
|
|
29
|
+
|
|
30
|
+
## Returns
|
|
31
|
+
|
|
32
|
+
* a sprite [kind](/reference/sprites/sprite/kind) object for a sprite kind identifer.
|
|
33
|
+
|
|
34
|
+
## Example #example
|
|
35
|
+
|
|
36
|
+
Create several `Food` sprites at random locations on the screen. Use a sprite kind object for the `Food` identifier to destroy all `Food` srprites.
|
|
37
|
+
|
|
38
|
+
```blocks
|
|
39
|
+
let mySprite: Sprite = null
|
|
40
|
+
let foodKind = SpriteKind.Food
|
|
41
|
+
for (let index = 0; index <= 4; index++) {
|
|
42
|
+
mySprite = sprites.create(img`
|
|
43
|
+
. . . . c c c b b b b b . . . .
|
|
44
|
+
. . c c b 4 4 4 4 4 4 b b b . .
|
|
45
|
+
. c c 4 4 4 4 4 5 4 4 4 4 b c .
|
|
46
|
+
. e 4 4 4 4 4 4 4 4 4 5 4 4 e .
|
|
47
|
+
e b 4 5 4 4 5 4 4 4 4 4 4 4 b c
|
|
48
|
+
e b 4 4 4 4 4 4 4 4 4 4 5 4 4 e
|
|
49
|
+
e b b 4 4 4 4 4 4 4 4 4 4 4 b e
|
|
50
|
+
. e b 4 4 4 4 4 5 4 4 4 4 b e .
|
|
51
|
+
8 7 e e b 4 4 4 4 4 4 b e e 6 8
|
|
52
|
+
8 7 2 e e e e e e e e e e 2 7 8
|
|
53
|
+
e 6 6 2 2 2 2 2 2 2 2 2 2 6 c e
|
|
54
|
+
e c 6 7 6 6 7 7 7 6 6 7 6 c c e
|
|
55
|
+
e b e 8 8 c c 8 8 c c c 8 e b e
|
|
56
|
+
e e b e c c e e e e e c e b e e
|
|
57
|
+
. e e b b 4 4 4 4 4 4 4 4 e e .
|
|
58
|
+
. . . c c c c c e e e e e . . .
|
|
59
|
+
`, SpriteKind.Food)
|
|
60
|
+
mySprite.setPosition(randint(0, scene.screenWidth()), randint(0, scene.screenHeight()))
|
|
61
|
+
}
|
|
62
|
+
for (let value of sprites.allOfKind(foodKind)) {
|
|
63
|
+
pause(1000)
|
|
64
|
+
value.destroy()
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## See also #seealso
|
|
69
|
+
|
|
70
|
+
[kind](/reference/sprites/sprite/kind)
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# get Neighboring Location
|
|
2
|
+
|
|
3
|
+
Get the location of a tile next to this one.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
tiles.getTileLocation(0, 0).getNeighboringLocation(CollisionDirection.Top)
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
A neighboring tile is one that is immediately to the `left`, `right`, `top`, or `bottom` side of the current tile. You can specify the side of the neighboring tile you want the location for.
|
|
10
|
+
|
|
11
|
+
## Parameters
|
|
12
|
+
|
|
13
|
+
* **direction**: the direction side for the neighbor tile from this tile. The directions to choose from are `left`, `right`, `top`, or `bottom`.
|
|
14
|
+
|
|
15
|
+
## Returns
|
|
16
|
+
|
|
17
|
+
* a [location](/reference/tiles/location) object for the neighbor tile.
|
|
18
|
+
|
|
19
|
+
## Example #example
|
|
20
|
+
|
|
21
|
+
Rotate a donut sprite around adjacent tiles in a tilemap.
|
|
22
|
+
|
|
23
|
+
```blocks
|
|
24
|
+
let nextSpot: tiles.Location = null
|
|
25
|
+
let rotation = 0
|
|
26
|
+
tiles.setCurrentTilemap(tilemap`level1`)
|
|
27
|
+
let mySprite = sprites.create(img`
|
|
28
|
+
. . . . . . b b b b a a . . . .
|
|
29
|
+
. . . . b b d d d 3 3 3 a a . .
|
|
30
|
+
. . . b d d d 3 3 3 3 3 3 a a .
|
|
31
|
+
. . b d d 3 3 3 3 3 3 3 3 3 a .
|
|
32
|
+
. b 3 d 3 3 3 3 3 b 3 3 3 3 a b
|
|
33
|
+
. b 3 3 3 3 3 a a 3 3 3 3 3 a b
|
|
34
|
+
b 3 3 3 3 3 a a 3 3 3 3 d a 4 b
|
|
35
|
+
b 3 3 3 3 b a 3 3 3 3 3 d a 4 b
|
|
36
|
+
b 3 3 3 3 3 3 3 3 3 3 d a 4 4 e
|
|
37
|
+
a 3 3 3 3 3 3 3 3 3 d a 4 4 4 e
|
|
38
|
+
a 3 3 3 3 3 3 3 d d a 4 4 4 e .
|
|
39
|
+
a a 3 3 3 d d d a a 4 4 4 e e .
|
|
40
|
+
. e a a a a a a 4 4 4 4 e e . .
|
|
41
|
+
. . e e b b 4 4 4 4 b e e . . .
|
|
42
|
+
. . . e e e e e e e e . . . . .
|
|
43
|
+
. . . . . . . . . . . . . . . .
|
|
44
|
+
`, SpriteKind.Player)
|
|
45
|
+
mySprite.x = mySprite.x - mySprite.width
|
|
46
|
+
game.onUpdateInterval(1000, function () {
|
|
47
|
+
if (rotation == 0) {
|
|
48
|
+
nextSpot = mySprite.tilemapLocation().getNeighboringLocation(CollisionDirection.Right)
|
|
49
|
+
} else if (rotation == 1) {
|
|
50
|
+
nextSpot = mySprite.tilemapLocation().getNeighboringLocation(CollisionDirection.Bottom)
|
|
51
|
+
} else if (rotation == 2) {
|
|
52
|
+
nextSpot = mySprite.tilemapLocation().getNeighboringLocation(CollisionDirection.Left)
|
|
53
|
+
} else {
|
|
54
|
+
nextSpot = mySprite.tilemapLocation().getNeighboringLocation(CollisionDirection.Top)
|
|
55
|
+
}
|
|
56
|
+
mySprite.setPosition(nextSpot.x, nextSpot.y)
|
|
57
|
+
rotation += 1
|
|
58
|
+
if (rotation > 3) {
|
|
59
|
+
rotation = 0
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## See also #seealso
|
|
65
|
+
|
|
66
|
+
[get tile location](/reference/tiles/get-tile-location)
|
|
67
|
+
|
|
68
|
+
```jres
|
|
69
|
+
{
|
|
70
|
+
"transparency16": {
|
|
71
|
+
"data": "hwQQABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
|
|
72
|
+
"mimeType": "image/x-mkcd-f4",
|
|
73
|
+
"tilemapTile": true
|
|
74
|
+
},
|
|
75
|
+
"tile1": {
|
|
76
|
+
"data": "hwQQABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
|
|
77
|
+
"mimeType": "image/x-mkcd-f4",
|
|
78
|
+
"tilemapTile": true,
|
|
79
|
+
"displayName": "myTile"
|
|
80
|
+
},
|
|
81
|
+
"tile2": {
|
|
82
|
+
"data": "hwQQABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
|
|
83
|
+
"mimeType": "image/x-mkcd-f4",
|
|
84
|
+
"tilemapTile": true,
|
|
85
|
+
"displayName": "myTile0"
|
|
86
|
+
},
|
|
87
|
+
"tile3": {
|
|
88
|
+
"data": "hwQQABAAAABERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERA==",
|
|
89
|
+
"mimeType": "image/x-mkcd-f4",
|
|
90
|
+
"tilemapTile": true,
|
|
91
|
+
"displayName": "myTile1"
|
|
92
|
+
},
|
|
93
|
+
"tile4": {
|
|
94
|
+
"data": "hwQQABAAAAB3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3dw==",
|
|
95
|
+
"mimeType": "image/x-mkcd-f4",
|
|
96
|
+
"tilemapTile": true,
|
|
97
|
+
"displayName": "myTile2"
|
|
98
|
+
},
|
|
99
|
+
"tile5": {
|
|
100
|
+
"data": "hwQQABAAAACqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqg==",
|
|
101
|
+
"mimeType": "image/x-mkcd-f4",
|
|
102
|
+
"tilemapTile": true,
|
|
103
|
+
"displayName": "myTile3"
|
|
104
|
+
},
|
|
105
|
+
"level1": {
|
|
106
|
+
"id": "level1",
|
|
107
|
+
"mimeType": "application/mkcd-tilemap",
|
|
108
|
+
"data": "MTAwYTAwMDgwMDAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMzAyMDMwMjAzMDIwMzAyMDEwMTAyMDMwMjAzMDIwMzAyMDMwMTAxMDMwMjAzMDIwMzAyMDMwMjAxMDEwMjAzMDIwMzAyMDMwMjAzMDEwMTAzMDIwMzAyMDMwMjAzMDIwMTAxMDIwMzAyMDMwMjAzMDIwMzAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMA==",
|
|
109
|
+
"tileset": [
|
|
110
|
+
"myTiles.transparency16",
|
|
111
|
+
"myTiles.tile3",
|
|
112
|
+
"myTiles.tile4",
|
|
113
|
+
"myTiles.tile5"
|
|
114
|
+
],
|
|
115
|
+
"displayName": "level1"
|
|
116
|
+
},
|
|
117
|
+
"*": {
|
|
118
|
+
"mimeType": "image/x-mkcd-f4",
|
|
119
|
+
"dataEncoding": "base64",
|
|
120
|
+
"namespace": "myTiles"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
@@ -1,51 +1,92 @@
|
|
|
1
1
|
# get Tile Location
|
|
2
2
|
|
|
3
|
-
Get
|
|
3
|
+
Get the tile location object for a particular column and row position in the tilemap.
|
|
4
4
|
|
|
5
5
|
```sig
|
|
6
6
|
tiles.getTileLocation(0, 0)
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
+
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.
|
|
10
|
+
|
|
9
11
|
## Parameters
|
|
10
12
|
|
|
11
|
-
* **col**: the column of the tile
|
|
12
|
-
* **row**: the row of the tile
|
|
13
|
+
* **col**: a [number](/types/number) that is the tilemap column of the tile location.
|
|
14
|
+
* **row**: a [number](/types/number) that is the tilemap row of the tile location.
|
|
13
15
|
|
|
14
16
|
## Returns
|
|
15
17
|
|
|
16
|
-
* a [
|
|
18
|
+
* a tile [location](/reference/tiles/location) object for a given column and row in the tilemap.
|
|
17
19
|
|
|
18
20
|
## Example #example
|
|
19
21
|
|
|
20
|
-
Make a
|
|
22
|
+
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.
|
|
21
23
|
|
|
22
24
|
```blocks
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
25
|
+
tiles.setTilemap(tilemap`level1`)
|
|
26
|
+
let mySprite = sprites.create(img`
|
|
27
|
+
. . . . . . . . . . . . . . . .
|
|
28
|
+
. . . . . . . . . . . . . . . .
|
|
29
|
+
. . . . . 7 7 7 7 7 7 . . . . .
|
|
30
|
+
. . . 7 7 7 7 7 7 7 7 7 7 . . .
|
|
31
|
+
. . . 7 7 7 7 7 7 7 7 7 7 . . .
|
|
32
|
+
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
|
|
33
|
+
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
|
|
34
|
+
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
|
|
35
|
+
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
|
|
36
|
+
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
|
|
37
|
+
. . 7 7 7 7 7 7 7 7 7 7 7 7 . .
|
|
38
|
+
. . . 7 7 7 7 7 7 7 7 7 7 . . .
|
|
39
|
+
. . . 7 7 7 7 7 7 7 7 7 7 . . .
|
|
40
|
+
. . . . . 7 7 7 7 7 7 . . . . .
|
|
41
|
+
. . . . . . . . . . . . . . . .
|
|
42
|
+
. . . . . . . . . . . . . . . .
|
|
43
|
+
`, SpriteKind.Player)
|
|
44
|
+
|
|
45
|
+
forever(function () {
|
|
46
|
+
tiles.placeOnTile(mySprite, tiles.getTileLocation(randint(0, 9), randint(0, 6)))
|
|
47
|
+
pause(500)
|
|
48
|
+
})
|
|
46
49
|
```
|
|
47
50
|
|
|
48
51
|
## See also #seealso
|
|
49
52
|
|
|
50
|
-
[
|
|
51
|
-
[
|
|
53
|
+
[set tile at](/reference/tiles/set-tile-at),
|
|
54
|
+
[place on tile](/reference/tiles/place-on-tile)
|
|
55
|
+
|
|
56
|
+
```jres
|
|
57
|
+
{
|
|
58
|
+
"transparency16": {
|
|
59
|
+
"data": "hwQQABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
|
|
60
|
+
"mimeType": "image/x-mkcd-f4",
|
|
61
|
+
"tilemapTile": true
|
|
62
|
+
},
|
|
63
|
+
"tile1": {
|
|
64
|
+
"data": "hwQQABAAAADd3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3Q==",
|
|
65
|
+
"mimeType": "image/x-mkcd-f4",
|
|
66
|
+
"tilemapTile": true,
|
|
67
|
+
"displayName": "myTile"
|
|
68
|
+
},
|
|
69
|
+
"tile2": {
|
|
70
|
+
"data": "hwQQABAAAABVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVQ==",
|
|
71
|
+
"mimeType": "image/x-mkcd-f4",
|
|
72
|
+
"tilemapTile": true,
|
|
73
|
+
"displayName": "myTile0"
|
|
74
|
+
},
|
|
75
|
+
"level1": {
|
|
76
|
+
"id": "level1",
|
|
77
|
+
"mimeType": "application/mkcd-tilemap",
|
|
78
|
+
"data": "MTAwYTAwMDgwMDAxMDIwMTAyMDEwMjAxMDIwMTAyMDIwMTAyMDEwMjAxMDIwMTAyMDEwMTAyMDEwMjAxMDIwMTAyMDEwMjAyMDEwMjAxMDIwMTAyMDEwMjAxMDEwMjAxMDIwMTAyMDEwMjAxMDIwMjAxMDIwMTAyMDEwMjAxMDIwMTAxMDIwMTAyMDEwMjAxMDIwMTAyMDIwMTAyMDEwMjAxMDIwMTAyMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMA==",
|
|
79
|
+
"tileset": [
|
|
80
|
+
"myTiles.transparency16",
|
|
81
|
+
"myTiles.tile1",
|
|
82
|
+
"myTiles.tile2"
|
|
83
|
+
],
|
|
84
|
+
"displayName": "level1"
|
|
85
|
+
},
|
|
86
|
+
"*": {
|
|
87
|
+
"mimeType": "image/x-mkcd-f4",
|
|
88
|
+
"dataEncoding": "base64",
|
|
89
|
+
"namespace": "myTiles"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
@@ -1,52 +1,86 @@
|
|
|
1
1
|
# get Tiles By Type
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Return an array of tile locations from the tilemap that contain the specified tile.
|
|
4
4
|
|
|
5
5
|
```sig
|
|
6
|
-
tiles.getTilesByType(
|
|
6
|
+
tiles.getTilesByType(null)
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
All the locations in the tilemap with the chosen **image** are returned in an array of [tiles](/types/tile). You can use this array to change or replace the tiles as one group.
|
|
10
|
-
|
|
11
9
|
## Parameters
|
|
12
10
|
|
|
13
|
-
* **
|
|
11
|
+
* **tile**: a tile [image](/types/image) to search the tilemap for.
|
|
14
12
|
|
|
15
13
|
## Returns
|
|
16
14
|
|
|
17
|
-
* an [array](/types/array) of
|
|
15
|
+
* an [array](/types/array) of tile locations from the tilemap that have the tile specified in **tile**.
|
|
18
16
|
|
|
19
17
|
## Example #example
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
Make a column of tiles from top to bottom of the screen. Set a sprite in motion and set it to bounce on walls. Every `5` seconds, find the column tiles in the tilemap and set them as either wall tiles or regular tiles.
|
|
22
20
|
|
|
23
21
|
```blocks
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
22
|
+
let isWall = false
|
|
23
|
+
tiles.setTilemap(tilemap`level1`)
|
|
24
|
+
let mySprite = sprites.create(img`
|
|
25
|
+
. . . . . . . . . . . . . . . .
|
|
26
|
+
. . . . . . . . . . . . . . . .
|
|
27
|
+
. . . . . 1 1 1 1 1 1 . . . . .
|
|
28
|
+
. . . 1 1 2 2 2 2 2 2 1 1 . . .
|
|
29
|
+
. . . 1 2 2 2 2 2 2 2 2 1 . . .
|
|
30
|
+
. . 1 2 2 2 2 2 2 2 2 2 2 1 . .
|
|
31
|
+
. . 1 2 2 2 2 2 2 2 2 2 2 1 . .
|
|
32
|
+
. . 1 2 2 2 2 2 2 2 2 2 2 1 . .
|
|
33
|
+
. . 1 2 2 2 2 2 2 2 2 2 2 1 . .
|
|
34
|
+
. . 1 2 2 2 2 2 2 2 2 2 2 1 . .
|
|
35
|
+
. . 1 2 2 2 2 2 2 2 2 2 2 1 . .
|
|
36
|
+
. . . 1 2 2 2 2 2 2 2 2 1 . . .
|
|
37
|
+
. . . 1 1 2 2 2 2 2 2 1 1 . . .
|
|
38
|
+
. . . . . 1 1 1 1 1 1 . . . . .
|
|
39
|
+
. . . . . . . . . . . . . . . .
|
|
40
|
+
. . . . . . . . . . . . . . . .
|
|
41
|
+
`, SpriteKind.Player)
|
|
42
|
+
mySprite.setBounceOnWall(true)
|
|
43
|
+
mySprite.vx = 80
|
|
44
|
+
mySprite.vy = 70
|
|
45
|
+
game.onUpdateInterval(5000, function () {
|
|
46
|
+
isWall = !(isWall)
|
|
47
|
+
for (let wallTile of tiles.getTilesByType(assets.tile`myTile`)) {
|
|
48
|
+
tiles.setWallAt(wallTile, isWall)
|
|
49
|
+
}
|
|
50
|
+
})
|
|
47
51
|
```
|
|
48
52
|
|
|
49
53
|
## See also #seealso
|
|
50
54
|
|
|
51
|
-
[get tile location](/reference/tiles/get-tile-location)
|
|
52
|
-
|
|
55
|
+
[get tile location](/reference/tiles/get-tile-location)
|
|
56
|
+
|
|
57
|
+
```jres
|
|
58
|
+
{
|
|
59
|
+
"transparency16": {
|
|
60
|
+
"data": "hwQQABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
|
|
61
|
+
"mimeType": "image/x-mkcd-f4",
|
|
62
|
+
"tilemapTile": true
|
|
63
|
+
},
|
|
64
|
+
"tile1": {
|
|
65
|
+
"data": "hwQQABAAAADu7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7g==",
|
|
66
|
+
"mimeType": "image/x-mkcd-f4",
|
|
67
|
+
"tilemapTile": true,
|
|
68
|
+
"displayName": "myTile"
|
|
69
|
+
},
|
|
70
|
+
"level1": {
|
|
71
|
+
"id": "level1",
|
|
72
|
+
"mimeType": "application/mkcd-tilemap",
|
|
73
|
+
"data": "MTAwYTAwMDgwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAxMDAwMDAwMDAwMDAwMDAwMDAxMDAwMDAwMDAwMDAwMDAwMDAwMDAwMTAwMDAwMDAwMDAwMDAwMDAwMTAwMDAwMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAxMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMA==",
|
|
74
|
+
"tileset": [
|
|
75
|
+
"myTiles.transparency16",
|
|
76
|
+
"myTiles.tile1"
|
|
77
|
+
],
|
|
78
|
+
"displayName": "level1"
|
|
79
|
+
},
|
|
80
|
+
"*": {
|
|
81
|
+
"mimeType": "image/x-mkcd-f4",
|
|
82
|
+
"dataEncoding": "base64",
|
|
83
|
+
"namespace": "myTiles"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|