pxt-common-packages 9.5.1 → 9.5.2
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/libs/azureiot/built/debug/binary.js +485 -485
- 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 +8384 -7819
- package/libs/controller---none/built/debug/binary.js +8363 -7798
- 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 +486 -486
- package/libs/game/_locales/game-jsdoc-strings.json +6 -0
- package/libs/game/built/debug/binary.js +8276 -7711
- package/libs/game/controllerbutton.ts +98 -1
- package/libs/game/docs/reference/scene/get-neighboring-location.md +123 -0
- package/libs/game/docs/reference/scene/get-tile-location.md +1 -5
- package/libs/game/docs/reference/scene/location.md +246 -0
- package/libs/game/docs/reference/scene/tile-at-location-equals.md +1 -1
- package/libs/game/docs/reference/scene/tile-at-location-is-wall.md +98 -0
- package/libs/game/docs/reference/scene/tile-image-at-location.md +65 -0
- package/libs/game/docs/reference/scene/tilemap-location.md +83 -0
- package/libs/game/docs/reference/sprites/destroy-all-sprites-of-kind.md +74 -0
- package/libs/game/docs/reference/sprites/sprite/change-scale.md +65 -0
- package/libs/game/docs/reference/sprites/sprite/fx.md +25 -25
- package/libs/game/docs/reference/sprites/sprite/fy.md +24 -24
- package/libs/game/docs/reference/sprites/sprite/scale.md +80 -0
- package/libs/game/docs/reference/sprites/sprite/set-scale.md +79 -0
- package/libs/game/docs/reference/sprites/sprite/sx.md +80 -0
- package/libs/game/docs/reference/sprites/sprite/sy.md +80 -0
- package/libs/game/docs/reference/sprites.md +12 -2
- package/libs/game/scene.ts +2 -0
- package/libs/game/sprite.ts +2 -2
- package/libs/game/sprites.ts +1 -1
- package/libs/game/tilemap.ts +88 -4
- 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 +200 -200
- package/libs/net/built/debug/binary.js +200 -200
- package/libs/net-game/built/debug/binary.js +10081 -9516
- package/libs/palette/built/debug/binary.js +8275 -7710
- 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/built/debug/binary.js +8 -8
- package/libs/radio-broadcast/built/debug/binary.js +8 -8
- 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 +8275 -7710
- package/libs/sprite-scaling/docs/reference/sprites/scaling/scale-by-percent.md +77 -0
- package/libs/sprite-scaling/docs/reference/sprites/scaling/scale-by-pixels.md +144 -0
- package/libs/sprite-scaling/docs/reference/sprites/scaling/scale-to-percent.md +83 -0
- package/libs/sprite-scaling/docs/reference/sprites/scaling/scale-to-pixels.md +140 -0
- package/libs/sprite-scaling/scaling.ts +5 -5
- package/libs/storyboard/built/debug/binary.js +8275 -7710
- package/package.json +1 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# tilemap Location
|
|
2
|
+
|
|
3
|
+
Get the location of a sprite on the tilemap.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
sprites.create(null).tilemapLocation()
|
|
7
|
+
```
|
|
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
|
+
|
|
11
|
+
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.
|
|
12
|
+
|
|
13
|
+
## Returns
|
|
14
|
+
|
|
15
|
+
* a tile [location](/reference/scene/location) object for the location of the sprite on the tilemap.
|
|
16
|
+
|
|
17
|
+
## Example #example
|
|
18
|
+
|
|
19
|
+
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.
|
|
20
|
+
|
|
21
|
+
```blocks
|
|
22
|
+
tiles.setCurrentTilemap(tilemap`level1`)
|
|
23
|
+
let mySprite = sprites.create(img`
|
|
24
|
+
. . 4 4 4 . . . . 4 4 4 . . . .
|
|
25
|
+
. 4 5 5 5 e . . e 5 5 5 4 . . .
|
|
26
|
+
4 5 5 5 5 5 e e 5 5 5 5 5 4 . .
|
|
27
|
+
4 5 5 4 4 5 5 5 5 4 4 5 5 4 . .
|
|
28
|
+
e 5 4 4 5 5 5 5 5 5 4 4 5 e . .
|
|
29
|
+
. e e 5 5 5 5 5 5 5 5 e e . . .
|
|
30
|
+
. . e 5 f 5 5 5 5 f 5 e . . . .
|
|
31
|
+
. . f 5 5 5 4 4 5 5 5 f . . f f
|
|
32
|
+
. . f 4 5 5 f f 5 5 6 f . f 5 f
|
|
33
|
+
. . . f 6 6 6 6 6 6 4 4 f 5 5 f
|
|
34
|
+
. . . f 4 5 5 5 5 5 5 4 4 5 f .
|
|
35
|
+
. . . f 5 5 5 5 5 4 5 5 f f . .
|
|
36
|
+
. . . f 5 f f f 5 f f 5 f . . .
|
|
37
|
+
. . . f f . . f f . . f f . . .
|
|
38
|
+
`, SpriteKind.Player)
|
|
39
|
+
let tmLocation = mySprite.tilemapLocation()
|
|
40
|
+
mySprite.sayText("col: " + tmLocation.column + " row: " + tmLocation.row)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## See also #seealso
|
|
44
|
+
|
|
45
|
+
[get tile location](/reference/scene/get-tile-location)
|
|
46
|
+
|
|
47
|
+
```jres
|
|
48
|
+
{
|
|
49
|
+
"transparency16": {
|
|
50
|
+
"data": "hwQQABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
|
|
51
|
+
"mimeType": "image/x-mkcd-f4",
|
|
52
|
+
"tilemapTile": true
|
|
53
|
+
},
|
|
54
|
+
"tile1": {
|
|
55
|
+
"data": "hwQQABAAAADu7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7u7g==",
|
|
56
|
+
"mimeType": "image/x-mkcd-f4",
|
|
57
|
+
"tilemapTile": true,
|
|
58
|
+
"displayName": "myTile"
|
|
59
|
+
},
|
|
60
|
+
"tile2": {
|
|
61
|
+
"data": "hwQQABAAAACZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmQ==",
|
|
62
|
+
"mimeType": "image/x-mkcd-f4",
|
|
63
|
+
"tilemapTile": true,
|
|
64
|
+
"displayName": "myTile0"
|
|
65
|
+
},
|
|
66
|
+
"level1": {
|
|
67
|
+
"id": "level1",
|
|
68
|
+
"mimeType": "application/mkcd-tilemap",
|
|
69
|
+
"data": "MTAwYTAwMDgwMDAyMDEwMjAxMDIwMTAyMDEwMjAxMDEwMjAxMDIwMTAyMDEwMjAxMDIwMjAxMDIwMTAyMDEwMjAxMDIwMTAxMDIwMTAyMDEwMjAxMDIwMTAyMDIwMTAyMDEwMjAxMDIwMTAyMDEwMTAyMDEwMjAxMDIwMTAyMDEwMjAyMDEwMjAxMDIwMTAyMDEwMjAxMDEwMjAxMDIwMTAyMDEwMjAxMDIwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMA==",
|
|
70
|
+
"tileset": [
|
|
71
|
+
"myTiles.transparency16",
|
|
72
|
+
"myTiles.tile1",
|
|
73
|
+
"myTiles.tile2"
|
|
74
|
+
],
|
|
75
|
+
"displayName": "level1"
|
|
76
|
+
},
|
|
77
|
+
"*": {
|
|
78
|
+
"mimeType": "image/x-mkcd-f4",
|
|
79
|
+
"dataEncoding": "base64",
|
|
80
|
+
"namespace": "myTiles"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# destroy All Sprites Of Kind
|
|
2
|
+
|
|
3
|
+
Destroy all the sprites of a certain kind.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
sprites.destroyAllSpritesOfKind(SpriteKind.Enemy)
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
You can destroy all of the current sprites of a particular kind. For example, you could explode all of the `Enemy` sprites in your game by destroying them with a disintegrating particle effect.
|
|
10
|
+
|
|
11
|
+
## Parameters
|
|
12
|
+
|
|
13
|
+
* **kind**: the kind of the sprites you want to destroy, such as `Player` or `Enemy`.
|
|
14
|
+
* **effect**: a particle effect to show when a sprite is destroyed.
|
|
15
|
+
* **duration**: the time in milliseconds that the **effect** will show.
|
|
16
|
+
|
|
17
|
+
## Example #example
|
|
18
|
+
|
|
19
|
+
Make a game where your player must avoid contact with `Blob` sprites to stay alive. Send the blobs at random speeds from the right side of the screen. Give your player a superpower to zap all of the current blobs with one press of button `A`.
|
|
20
|
+
|
|
21
|
+
```blocks
|
|
22
|
+
namespace SpriteKind {
|
|
23
|
+
export const Blob = SpriteKind.create()
|
|
24
|
+
}
|
|
25
|
+
controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
|
|
26
|
+
sprites.destroyAllSpritesOfKind(SpriteKind.Blob, effects.disintegrate, 100)
|
|
27
|
+
})
|
|
28
|
+
sprites.onOverlap(SpriteKind.Player, SpriteKind.Blob, function (sprite, otherSprite) {
|
|
29
|
+
info.changeLifeBy(-1)
|
|
30
|
+
})
|
|
31
|
+
let blob: Sprite = null
|
|
32
|
+
info.setLife(3)
|
|
33
|
+
let mySprite = sprites.create(img`
|
|
34
|
+
. . . . . f f f f . . . . .
|
|
35
|
+
. . . f f 5 5 5 5 f f . . .
|
|
36
|
+
. . f 5 5 5 5 5 5 5 5 f . .
|
|
37
|
+
. f 5 5 5 5 5 5 5 5 5 5 f .
|
|
38
|
+
. f 5 5 5 d b b d 5 5 5 f .
|
|
39
|
+
f 5 5 5 b 4 4 4 4 b 5 5 5 f
|
|
40
|
+
f 5 5 c c 4 4 4 4 c c 5 5 f
|
|
41
|
+
f b b f b f 4 4 f b f b b f
|
|
42
|
+
f b b 4 1 f d d f 1 4 b b f
|
|
43
|
+
. f b f d d d d d d f b f .
|
|
44
|
+
. f e f e 4 4 4 4 e f e f .
|
|
45
|
+
. e 4 f 6 9 9 9 9 6 f 4 e .
|
|
46
|
+
. 4 d c 9 9 9 9 9 9 c d 4 .
|
|
47
|
+
. 4 f b 3 b 3 b 3 b b f 4 .
|
|
48
|
+
. . f f 3 b 3 b 3 3 f f . .
|
|
49
|
+
. . . . f f b b f f . . . .
|
|
50
|
+
`, SpriteKind.Player)
|
|
51
|
+
controller.moveSprite(mySprite)
|
|
52
|
+
mySprite.left = 10
|
|
53
|
+
game.onUpdateInterval(500, function () {
|
|
54
|
+
blob = sprites.create(img`
|
|
55
|
+
. 2 2 2 . 2 2 .
|
|
56
|
+
2 2 5 2 2 2 2 2
|
|
57
|
+
2 f 2 2 5 2 2 .
|
|
58
|
+
2 2 2 2 2 2 2 2
|
|
59
|
+
2 2 2 2 2 2 2 2
|
|
60
|
+
2 2 f 2 f 2 2 2
|
|
61
|
+
. 2 2 2 2 2 2 .
|
|
62
|
+
. 2 . 2 2 5 2 .
|
|
63
|
+
`, SpriteKind.Blob)
|
|
64
|
+
blob.setFlag(SpriteFlag.AutoDestroy, true)
|
|
65
|
+
blob.setPosition(scene.screenWidth(), randint(0, scene.screenHeight()))
|
|
66
|
+
blob.vx = randint(-10, -50)
|
|
67
|
+
})
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## See also #seealso
|
|
71
|
+
|
|
72
|
+
[start effect](/reference/sprites/sprite/start-effect),
|
|
73
|
+
[destroy](/reference/sprites/sprite/destroy),
|
|
74
|
+
[on destroyed](/reference/sprites/on-destroyed),
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# change Scale
|
|
2
|
+
|
|
3
|
+
Change the scale factor for a sprite by an increment or decrement.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
sprites.create(null).changeScale(1, ScaleAnchor.Middle)
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
You can increase or decrease a sprite's size from it's current size by a certain amount. If a sprite's scale is `2` and you change it by `1`, then the sprite is now `3` times larger than it's original size. The sprite's size will shrink if you give a negative value. If you use `-2` for the change **value**, the sprite's new size will be half of what is was before.
|
|
10
|
+
|
|
11
|
+
The **anchor** determines which direction the sprite will expand or shrink. If you increase the scale from the `middle`, the sprite will grow equally from it's center. If you choose to scale from the `bottom left`, the sprite will grow toward the top right of the screen.
|
|
12
|
+
|
|
13
|
+
## Parameters
|
|
14
|
+
|
|
15
|
+
* **value**: a [number](/types/number) to change the sprite's scale by.
|
|
16
|
+
* **anchor**: an anchor point to scale the sprite from:
|
|
17
|
+
>* `middle`
|
|
18
|
+
>* `top`
|
|
19
|
+
>* `left`
|
|
20
|
+
>* `right`
|
|
21
|
+
>* `bottom`
|
|
22
|
+
>* `top left`
|
|
23
|
+
>* `top right`
|
|
24
|
+
>* `bottom right`
|
|
25
|
+
>* `bottom left`
|
|
26
|
+
|
|
27
|
+
## Examples #example
|
|
28
|
+
|
|
29
|
+
### Rescale sprite
|
|
30
|
+
|
|
31
|
+
Create a sprite with a square image. In a game update event, make the sprite grow and shrink continuously.
|
|
32
|
+
|
|
33
|
+
```blocks
|
|
34
|
+
let scaleFactor = 0
|
|
35
|
+
let mySprite = sprites.create(img`
|
|
36
|
+
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
|
|
37
|
+
2 5 5 5 7 7 7 7 7 7 7 7 5 5 5 2
|
|
38
|
+
2 5 5 7 7 7 7 7 7 7 7 7 7 5 5 2
|
|
39
|
+
2 5 7 7 7 7 7 7 7 7 7 7 7 7 5 2
|
|
40
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
41
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
42
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
43
|
+
2 7 7 7 7 7 7 8 8 7 7 7 7 7 7 2
|
|
44
|
+
2 7 7 7 7 7 7 8 8 7 7 7 7 7 7 2
|
|
45
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
46
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
47
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
48
|
+
2 5 7 7 7 7 7 7 7 7 7 7 7 7 5 2
|
|
49
|
+
2 5 5 7 7 7 7 7 7 7 7 7 7 5 5 2
|
|
50
|
+
2 5 5 5 7 7 7 7 7 7 7 7 5 5 5 2
|
|
51
|
+
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
|
|
52
|
+
`, SpriteKind.Player)
|
|
53
|
+
game.onUpdateInterval(500, function () {
|
|
54
|
+
if (mySprite.scale == 1) {
|
|
55
|
+
scaleFactor = 1
|
|
56
|
+
} else if (mySprite.scale == 7) {
|
|
57
|
+
scaleFactor = -1
|
|
58
|
+
}
|
|
59
|
+
mySprite.changeScale(scaleFactor, ScaleAnchor.Middle)
|
|
60
|
+
})
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## See also #seealso
|
|
64
|
+
|
|
65
|
+
[set scale](/reference/sprites/sprite/set-scale)
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
#
|
|
1
|
+
# fx (property)
|
|
2
2
|
|
|
3
|
-
Get or set the friction opposing a sprite's motion in the
|
|
3
|
+
Get or set the friction opposing a sprite's motion in the horizontal direction.
|
|
4
4
|
|
|
5
5
|
## Get
|
|
6
6
|
|
|
7
|
-
Get the
|
|
7
|
+
Get the horizontal friction on the sprite.
|
|
8
8
|
|
|
9
9
|
```block
|
|
10
10
|
let mySprite: Sprite = null
|
|
11
11
|
|
|
12
|
-
let horzAccel = mySprite.
|
|
12
|
+
let horzAccel = mySprite.fx
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
```typescript-ignorelet
|
|
16
|
-
horzAccel = mySprite.
|
|
16
|
+
horzAccel = mySprite.fx
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
### Returns
|
|
20
20
|
|
|
21
|
-
* a [number](/types/number) that is the current
|
|
21
|
+
* a [number](/types/number) that is the current horizontal friction of the sprite.
|
|
22
22
|
|
|
23
23
|
## Set
|
|
24
24
|
|
|
25
|
-
Set the
|
|
25
|
+
Set the horizontal friction for the sprite.
|
|
26
26
|
|
|
27
27
|
```block
|
|
28
28
|
let mySprite: Sprite = null
|
|
29
29
|
|
|
30
|
-
mySprite.
|
|
30
|
+
mySprite.fx = 0
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
```typescript-ignore
|
|
34
|
-
mySprite.
|
|
34
|
+
mySprite.fx = 0
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
### Parameter
|
|
38
38
|
|
|
39
|
-
* **value**: the new
|
|
39
|
+
* **value**: the new horizontal friction opposing the sprite's motion in pixels per second, per second.
|
|
40
40
|
|
|
41
|
-
## Sprite
|
|
41
|
+
## Sprite horizontal friction
|
|
42
42
|
|
|
43
|
-
Friction is an opposing force against the motion of a sprite. If a sprite has a
|
|
43
|
+
Friction is an opposing force against the motion of a sprite. If a sprite has a horizontal velocity (`vx`), it's friction will slow the sprite down until it's horizontal velocity becomes `0`. This is similar to setting an opposite horizontal acceleration but the opposite acceleration goes away once the sprite stops.
|
|
44
44
|
|
|
45
45
|
## Examples #example
|
|
46
46
|
|
|
47
47
|
### Measure stopping time #ex1
|
|
48
48
|
|
|
49
|
-
Move the sprite from
|
|
49
|
+
Move the sprite from left to right across the screen. Use the correct amount of friction (`fx`) to make the sprite stop at `3` seconds.
|
|
50
50
|
|
|
51
51
|
```blocks
|
|
52
52
|
let stopTime = 0
|
|
@@ -70,13 +70,13 @@ let mySprite = sprites.create(img`
|
|
|
70
70
|
. . . . . . . . . . . . . . . .
|
|
71
71
|
`, SpriteKind.Player)
|
|
72
72
|
mySprite.setStayInScreen(true)
|
|
73
|
-
mySprite.
|
|
74
|
-
mySprite.
|
|
75
|
-
mySprite.
|
|
73
|
+
mySprite.left = 0
|
|
74
|
+
mySprite.fx = 30
|
|
75
|
+
mySprite.vx = 90
|
|
76
76
|
game.onUpdateInterval(100, function () {
|
|
77
77
|
if (counting) {
|
|
78
78
|
stopTime += 0.1
|
|
79
|
-
if (mySprite.
|
|
79
|
+
if (mySprite.vx == 0) {
|
|
80
80
|
counting = false
|
|
81
81
|
mySprite.sayText("" + stopTime + "sec", 5000, false)
|
|
82
82
|
}
|
|
@@ -84,9 +84,9 @@ game.onUpdateInterval(100, function () {
|
|
|
84
84
|
})
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
###
|
|
87
|
+
### Skipping sprite #ex2
|
|
88
88
|
|
|
89
|
-
Make a sprite move from the
|
|
89
|
+
Make a sprite move from the left to the right. Make it skip to the right once every second.
|
|
90
90
|
|
|
91
91
|
```blocks
|
|
92
92
|
let mySprite = sprites.create(img`
|
|
@@ -108,16 +108,16 @@ let mySprite = sprites.create(img`
|
|
|
108
108
|
. . . . . . . . . . . . . . . .
|
|
109
109
|
`, SpriteKind.Player)
|
|
110
110
|
mySprite.setStayInScreen(true)
|
|
111
|
-
mySprite.
|
|
112
|
-
mySprite.
|
|
113
|
-
mySprite.
|
|
111
|
+
mySprite.left = 0
|
|
112
|
+
mySprite.fx = 80
|
|
113
|
+
mySprite.vx = 80
|
|
114
114
|
for (let index = 0; index < 3; index++) {
|
|
115
|
-
mySprite.
|
|
115
|
+
mySprite.vx = 80
|
|
116
116
|
pause(1000)
|
|
117
117
|
}
|
|
118
118
|
```
|
|
119
119
|
|
|
120
120
|
## See also #seealso
|
|
121
121
|
|
|
122
|
-
[
|
|
123
|
-
[
|
|
122
|
+
[fy](/reference/sprites/sprite/fy),
|
|
123
|
+
[ax](/reference/sprites/sprite/ax)
|
|
@@ -1,52 +1,52 @@
|
|
|
1
1
|
# fy (property)
|
|
2
2
|
|
|
3
|
-
Get or set the friction opposing a sprite's motion in the
|
|
3
|
+
Get or set the friction opposing a sprite's motion in the vertical direction.
|
|
4
4
|
|
|
5
5
|
## Get
|
|
6
6
|
|
|
7
|
-
Get the
|
|
7
|
+
Get the vertical friction on the sprite.
|
|
8
8
|
|
|
9
9
|
```block
|
|
10
10
|
let mySprite: Sprite = null
|
|
11
11
|
|
|
12
|
-
let horzAccel = mySprite.
|
|
12
|
+
let horzAccel = mySprite.fy
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
```typescript-ignorelet
|
|
16
|
-
horzAccel = mySprite.
|
|
16
|
+
horzAccel = mySprite.fy
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
### Returns
|
|
20
20
|
|
|
21
|
-
* a [number](/types/number) that is the current
|
|
21
|
+
* a [number](/types/number) that is the current vertical friction of the sprite.
|
|
22
22
|
|
|
23
23
|
## Set
|
|
24
24
|
|
|
25
|
-
Set the
|
|
25
|
+
Set the vertical friction for the sprite.
|
|
26
26
|
|
|
27
27
|
```block
|
|
28
28
|
let mySprite: Sprite = null
|
|
29
29
|
|
|
30
|
-
mySprite.
|
|
30
|
+
mySprite.fy = 0
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
```typescript-ignore
|
|
34
|
-
mySprite.
|
|
34
|
+
mySprite.fy = 0
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
### Parameter
|
|
38
38
|
|
|
39
|
-
* **value**: the new
|
|
39
|
+
* **value**: the new vertical friction opposing the sprite's motion in pixels per second, per second.
|
|
40
40
|
|
|
41
|
-
## Sprite
|
|
41
|
+
## Sprite vertical friction
|
|
42
42
|
|
|
43
|
-
Friction is an opposing force against the motion of a sprite. If a sprite has a
|
|
43
|
+
Friction is an opposing force against the motion of a sprite. If a sprite has a vertical velocity (`vy`), it's friction will slow the sprite down until it's vertical velocity becomes `0`. This is similar to setting an opposite vertical acceleration but the opposite acceleration goes away once the sprite stops.
|
|
44
44
|
|
|
45
45
|
## Examples #example
|
|
46
46
|
|
|
47
47
|
### Measure stopping time #ex1
|
|
48
48
|
|
|
49
|
-
Move the sprite from
|
|
49
|
+
Move the sprite from top to bottom across the screen. Use the correct amount of friction (`fy`) to make the sprite stop at `3` seconds.
|
|
50
50
|
|
|
51
51
|
```blocks
|
|
52
52
|
let stopTime = 0
|
|
@@ -70,13 +70,13 @@ let mySprite = sprites.create(img`
|
|
|
70
70
|
. . . . . . . . . . . . . . . .
|
|
71
71
|
`, SpriteKind.Player)
|
|
72
72
|
mySprite.setStayInScreen(true)
|
|
73
|
-
mySprite.
|
|
74
|
-
mySprite.
|
|
75
|
-
mySprite.
|
|
73
|
+
mySprite.top = 0
|
|
74
|
+
mySprite.fy = 20
|
|
75
|
+
mySprite.vy = 60
|
|
76
76
|
game.onUpdateInterval(100, function () {
|
|
77
77
|
if (counting) {
|
|
78
78
|
stopTime += 0.1
|
|
79
|
-
if (mySprite.
|
|
79
|
+
if (mySprite.vy == 0) {
|
|
80
80
|
counting = false
|
|
81
81
|
mySprite.sayText("" + stopTime + "sec", 5000, false)
|
|
82
82
|
}
|
|
@@ -84,9 +84,9 @@ game.onUpdateInterval(100, function () {
|
|
|
84
84
|
})
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
###
|
|
87
|
+
### Skipping sprite #ex2
|
|
88
88
|
|
|
89
|
-
Make a sprite move from the
|
|
89
|
+
Make a sprite move from the top to the bottom. Make it skip to the right once every second.
|
|
90
90
|
|
|
91
91
|
```blocks
|
|
92
92
|
let mySprite = sprites.create(img`
|
|
@@ -108,16 +108,16 @@ let mySprite = sprites.create(img`
|
|
|
108
108
|
. . . . . . . . . . . . . . . .
|
|
109
109
|
`, SpriteKind.Player)
|
|
110
110
|
mySprite.setStayInScreen(true)
|
|
111
|
-
mySprite.
|
|
112
|
-
mySprite.
|
|
113
|
-
mySprite.
|
|
111
|
+
mySprite.top = 0
|
|
112
|
+
mySprite.fy = 60
|
|
113
|
+
mySprite.vy = 60
|
|
114
114
|
for (let index = 0; index < 3; index++) {
|
|
115
|
-
mySprite.
|
|
115
|
+
mySprite.vy = 60
|
|
116
116
|
pause(1000)
|
|
117
117
|
}
|
|
118
118
|
```
|
|
119
119
|
|
|
120
120
|
## See also #seealso
|
|
121
121
|
|
|
122
|
-
[
|
|
123
|
-
[
|
|
122
|
+
[fx](/reference/sprites/sprite/fx),
|
|
123
|
+
[ay](/reference/sprites/sprite/ay)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# scale (property)
|
|
2
|
+
|
|
3
|
+
Get or set the scaling factor for the width and height of a sprite.
|
|
4
|
+
|
|
5
|
+
## Get
|
|
6
|
+
|
|
7
|
+
Get the scale for the sprite.
|
|
8
|
+
|
|
9
|
+
```block
|
|
10
|
+
let mySprite: Sprite = null
|
|
11
|
+
|
|
12
|
+
let xScale = mySprite.scale
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```typescript-ignorelet
|
|
16
|
+
xScale = mySprite.scale
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Returns
|
|
20
|
+
|
|
21
|
+
* a [number](/types/number) that is the current scale for the sprite.
|
|
22
|
+
|
|
23
|
+
## Set
|
|
24
|
+
|
|
25
|
+
Set the scale for the sprite.
|
|
26
|
+
|
|
27
|
+
```block
|
|
28
|
+
let mySprite: Sprite = null
|
|
29
|
+
|
|
30
|
+
mySprite.scale = 2
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```typescript-ignore
|
|
34
|
+
mySprite.scale = 2
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Parameter
|
|
38
|
+
|
|
39
|
+
* **value**: the new scale factor for the size of the sprite.
|
|
40
|
+
|
|
41
|
+
## Examples #example
|
|
42
|
+
|
|
43
|
+
### Stretch and shrink size #ex1
|
|
44
|
+
|
|
45
|
+
Scale a sprite's size by `1` more every second. Expand while it's small and contract when it's large.
|
|
46
|
+
|
|
47
|
+
```blocks
|
|
48
|
+
let expand = 0
|
|
49
|
+
let mySprite = sprites.create(img`
|
|
50
|
+
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
|
|
51
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
52
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
53
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
54
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
55
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
56
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
57
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
58
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
59
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
60
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
61
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
62
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
63
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
64
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
65
|
+
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
|
|
66
|
+
`, SpriteKind.Player)
|
|
67
|
+
game.onUpdateInterval(1000, function () {
|
|
68
|
+
if (mySprite.scale == 1) {
|
|
69
|
+
expand = 1
|
|
70
|
+
} else if (mySprite.scale == 6) {
|
|
71
|
+
expand = -1
|
|
72
|
+
}
|
|
73
|
+
mySprite.scale += expand
|
|
74
|
+
})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## See also #seealso
|
|
78
|
+
|
|
79
|
+
[sx](/reference/sprites/sprite/sx),
|
|
80
|
+
[sy](/reference/sprites/sprite/sy)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# set Scale
|
|
2
|
+
|
|
3
|
+
Set the scale factor for a sprite based on an anchor point.
|
|
4
|
+
|
|
5
|
+
```sig
|
|
6
|
+
sprites.create(null).setScale(1, ScaleAnchor.Middle)
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
You can increase or decrease a sprite from it's current size to a new size by setting a scale value. If a sprite's scale is set to `2`, then the sprite's new size is two times larger than it's original size. The sprite's size will shrink if you give a negative value. If you use `-3` for the scale value, the sprite's new size will three times smaller than it's original size.
|
|
10
|
+
|
|
11
|
+
The **anchor** determines which direction the sprite will expand or shrink. If you increase the scale from the `middle`, the sprite will grow equally from it's center. If you choose to scale from the `bottom left`, the sprite will grow toward the top right of the screen.
|
|
12
|
+
|
|
13
|
+
## Parameters
|
|
14
|
+
|
|
15
|
+
* **value**: a [number](/types/number) that is the scale factor for the sprite.
|
|
16
|
+
* **anchor**: an anchor point to scale the sprite from:
|
|
17
|
+
>* `middle`
|
|
18
|
+
>* `top`
|
|
19
|
+
>* `left`
|
|
20
|
+
>* `right`
|
|
21
|
+
>* `bottom`
|
|
22
|
+
>* `top left`
|
|
23
|
+
>* `top right`
|
|
24
|
+
>* `bottom right`
|
|
25
|
+
>* `bottom left`
|
|
26
|
+
|
|
27
|
+
## Examples #example
|
|
28
|
+
|
|
29
|
+
### Scale in 4 directions
|
|
30
|
+
|
|
31
|
+
Create a sprite with a square image. Make the sprite grow and shrink by `3` in each of the 4 corner directions.
|
|
32
|
+
|
|
33
|
+
```blocks
|
|
34
|
+
let scaleZone = 0
|
|
35
|
+
let mySprite = sprites.create(img`
|
|
36
|
+
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
|
|
37
|
+
2 5 5 5 7 7 7 7 7 7 7 7 5 5 5 2
|
|
38
|
+
2 5 5 7 7 7 7 7 7 7 7 7 7 5 5 2
|
|
39
|
+
2 5 7 7 7 7 7 7 7 7 7 7 7 7 5 2
|
|
40
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
41
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
42
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
43
|
+
2 7 7 7 7 7 7 8 8 7 7 7 7 7 7 2
|
|
44
|
+
2 7 7 7 7 7 7 8 8 7 7 7 7 7 7 2
|
|
45
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
46
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
47
|
+
2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
|
|
48
|
+
2 5 7 7 7 7 7 7 7 7 7 7 7 7 5 2
|
|
49
|
+
2 5 5 7 7 7 7 7 7 7 7 7 7 5 5 2
|
|
50
|
+
2 5 5 5 7 7 7 7 7 7 7 7 5 5 5 2
|
|
51
|
+
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
|
|
52
|
+
`, SpriteKind.Player)
|
|
53
|
+
game.onUpdateInterval(500, function () {
|
|
54
|
+
if (scaleZone == 0) {
|
|
55
|
+
mySprite.setScale(3, ScaleAnchor.TopLeft)
|
|
56
|
+
} else if (scaleZone == 1) {
|
|
57
|
+
mySprite.setScale(1, ScaleAnchor.TopLeft)
|
|
58
|
+
} else if (scaleZone == 2) {
|
|
59
|
+
mySprite.setScale(3, ScaleAnchor.TopRight)
|
|
60
|
+
} else if (scaleZone == 3) {
|
|
61
|
+
mySprite.setScale(1, ScaleAnchor.TopRight)
|
|
62
|
+
} else if (scaleZone == 4) {
|
|
63
|
+
mySprite.setScale(3, ScaleAnchor.BottomRight)
|
|
64
|
+
} else if (scaleZone == 5) {
|
|
65
|
+
mySprite.setScale(1, ScaleAnchor.BottomRight)
|
|
66
|
+
} else if (scaleZone == 6) {
|
|
67
|
+
mySprite.setScale(3, ScaleAnchor.BottomLeft)
|
|
68
|
+
} else if (scaleZone == 7) {
|
|
69
|
+
mySprite.setScale(1, ScaleAnchor.BottomLeft)
|
|
70
|
+
} else {
|
|
71
|
+
scaleZone = -1
|
|
72
|
+
}
|
|
73
|
+
scaleZone += 1
|
|
74
|
+
})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## See also #seealso
|
|
78
|
+
|
|
79
|
+
[change scale](/reference/sprites/sprite/change-scale)
|