pxt-common-packages 9.4.7 → 9.4.11

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.
Files changed (85) hide show
  1. package/built/common-sim.d.ts +1 -0
  2. package/built/common-sim.js +3 -0
  3. package/libs/accelerometer/built/debug/binary.js +8 -8
  4. package/libs/azureiot/built/debug/binary.js +485 -485
  5. package/libs/base/fixed.ts +6 -0
  6. package/libs/color/built/debug/binary.js +8 -8
  7. package/libs/color-sensor/built/debug/binary.js +8 -8
  8. package/libs/controller/built/debug/binary.js +8460 -7857
  9. package/libs/controller---none/built/debug/binary.js +8439 -7836
  10. package/libs/core/built/debug/binary.js +2 -2
  11. package/libs/core---samd/built/debug/binary.js +8 -8
  12. package/libs/datalogger/built/debug/binary.js +63 -63
  13. package/libs/edge-connector/built/debug/binary.js +8 -8
  14. package/libs/esp32/built/debug/binary.js +486 -486
  15. package/libs/game/_locales/game-jsdoc-strings.json +6 -0
  16. package/libs/game/built/debug/binary.js +8401 -7798
  17. package/libs/game/controllerbutton.ts +98 -1
  18. package/libs/game/docs/reference/scene/get-neighboring-location.md +123 -0
  19. package/libs/game/docs/reference/scene/get-tile-location.md +1 -5
  20. package/libs/game/docs/reference/scene/location.md +246 -0
  21. package/libs/game/docs/reference/scene/tile-at-location-equals.md +1 -1
  22. package/libs/game/docs/reference/scene/tile-at-location-is-wall.md +98 -0
  23. package/libs/game/docs/reference/scene/tile-image-at-location.md +65 -0
  24. package/libs/game/docs/reference/scene/tilemap-location.md +83 -0
  25. package/libs/game/docs/reference/sprites/destroy-all-sprites-of-kind.md +74 -0
  26. package/libs/game/docs/reference/sprites/sprite/change-scale.md +65 -0
  27. package/libs/game/docs/reference/sprites/sprite/fx.md +25 -25
  28. package/libs/game/docs/reference/sprites/sprite/fy.md +24 -24
  29. package/libs/game/docs/reference/sprites/sprite/scale.md +80 -0
  30. package/libs/game/docs/reference/sprites/sprite/set-scale.md +79 -0
  31. package/libs/game/docs/reference/sprites/sprite/sx.md +80 -0
  32. package/libs/game/docs/reference/sprites/sprite/sy.md +80 -0
  33. package/libs/game/docs/reference/sprites.md +12 -2
  34. package/libs/game/hitbox.ts +5 -5
  35. package/libs/game/scene.ts +2 -0
  36. package/libs/game/sprite.ts +7 -7
  37. package/libs/game/sprites.ts +1 -1
  38. package/libs/game/tilemap.ts +88 -4
  39. package/libs/gamepad/built/debug/binary.js +8 -8
  40. package/libs/keyboard/built/debug/binary.js +8 -8
  41. package/libs/lcd/built/debug/binary.js +8 -8
  42. package/libs/light/built/debug/binary.js +8 -8
  43. package/libs/light-spectrum-sensor/built/debug/binary.js +8 -8
  44. package/libs/lora/built/debug/binary.js +8 -8
  45. package/libs/matrix-keypad/built/debug/binary.js +8 -8
  46. package/libs/microphone/built/debug/binary.js +8 -8
  47. package/libs/mouse/built/debug/binary.js +8 -8
  48. package/libs/mqtt/built/debug/binary.js +200 -200
  49. package/libs/music/built/debug/binary.js +8 -8
  50. package/libs/net/built/debug/binary.js +200 -200
  51. package/libs/net/controller.ts +10 -1
  52. package/libs/net-game/built/debug/binary.js +10125 -9522
  53. package/libs/palette/built/debug/binary.js +8400 -7797
  54. package/libs/pixel/built/debug/binary.js +8 -8
  55. package/libs/power/built/debug/binary.js +8 -8
  56. package/libs/proximity/built/debug/binary.js +8 -8
  57. package/libs/pulse/built/debug/binary.js +8 -8
  58. package/libs/radio/built/debug/binary.js +8 -8
  59. package/libs/radio-broadcast/built/debug/binary.js +8 -8
  60. package/libs/rotary-encoder/built/debug/binary.js +8 -8
  61. package/libs/screen/built/debug/binary.js +50 -50
  62. package/libs/servo/built/debug/binary.js +8 -8
  63. package/libs/sprite-scaling/_locales/sprite-scaling-strings.json +5 -7
  64. package/libs/sprite-scaling/built/debug/binary.js +8400 -7797
  65. package/libs/sprite-scaling/docs/reference/sprites/scaling/scale-by-percent.md +77 -0
  66. package/libs/sprite-scaling/docs/reference/sprites/scaling/scale-by-pixels.md +144 -0
  67. package/libs/sprite-scaling/docs/reference/sprites/scaling/scale-to-percent.md +83 -0
  68. package/libs/sprite-scaling/docs/reference/sprites/scaling/scale-to-pixels.md +140 -0
  69. package/libs/sprite-scaling/scaling.ts +51 -50
  70. package/libs/storyboard/built/debug/binary.js +8400 -7797
  71. package/libs/tests/built/debug/binary.js +15 -15
  72. package/libs/thermometer/built/debug/binary.js +8 -8
  73. package/libs/wifi---esp32/README.md +12 -0
  74. package/libs/wifi---esp32/buildlogin.sh +1 -0
  75. package/libs/wifi---esp32/controller.ts +27 -1
  76. package/libs/wifi---esp32/enums.d.ts +4 -0
  77. package/libs/wifi---esp32/httpserver.cpp +168 -0
  78. package/libs/wifi---esp32/login.full.html +37 -0
  79. package/libs/wifi---esp32/login.html +1 -0
  80. package/libs/wifi---esp32/pxt.json +1 -0
  81. package/libs/wifi---esp32/shims.d.ts +8 -0
  82. package/libs/wifi---esp32/sim/wifisockets.ts +3 -0
  83. package/libs/wifi---esp32/wifi.cpp +24 -15
  84. package/libs/wifi---esp32/wifi.h +15 -1
  85. package/package.json +1 -1
@@ -0,0 +1,77 @@
1
+ # scale By Percent
2
+
3
+ Scale a sprite by a percentage of its current size in a direction from an anchor point.
4
+
5
+ ```sig
6
+ scaling.scaleByPercent(null, 50, ScaleDirection.Uniformly, ScaleAnchor.Middle)
7
+ ```
8
+
9
+ A sprite can scale by a percentage of its original size in a direction from an anchor point. The scaling can be in just one direction or the sprite can scale uniformly.
10
+
11
+ ## Uniform scaling
12
+
13
+ When the scaling **direction** is set to `uniformly`, the sprite is scaled so that the new size will have both the width and height changed by the same percentage **value**. If a sprite's current size is `64` x `32` and it's uniformly scaled by `50` percent, the new width is `32` and the new height is `16`.
14
+
15
+ ## Parameters
16
+
17
+ * **sprite**: the sprite to scale by a percentage of its original size.
18
+ * **value**: the [number](/types/number) that is the percentage to scale the sprite by.
19
+ * **direction**: the direction to scale in:
20
+ >* `horizontally`
21
+ >* `vertically`
22
+ >* `uniformly`
23
+ * **anchor**: an anchor point to scale the sprite from:
24
+ >* `middle`
25
+ >* `top`
26
+ >* `left`
27
+ >* `right`
28
+ >* `bottom`
29
+ >* `top left`
30
+ >* `top right`
31
+ >* `bottom right`
32
+ >* `bottom left`
33
+
34
+ ## Example #example
35
+
36
+ ### Scaling tester #ex1
37
+
38
+ Make a program to test sprite scaling a sprite by expanding and shrinking it uniformly. Use the controller buttons to increase and decrease the scale of a sprite by a percentage of its current size.
39
+
40
+ ```blocks
41
+ controller.B.onEvent(ControllerButtonEvent.Pressed, function () {
42
+ scaling.scaleByPercent(mySprite, -50, ScaleDirection.Uniformly, ScaleAnchor.Middle)
43
+ info.setScore(mySprite.width)
44
+ })
45
+ controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
46
+ scaling.scaleByPercent(mySprite, 50, ScaleDirection.Uniformly, ScaleAnchor.Middle)
47
+ info.setScore(mySprite.width)
48
+ })
49
+ let mySprite: Sprite = null
50
+ mySprite = sprites.create(img`
51
+ 22222222222222222222222222222222
52
+ 25557777777777777777777777775552
53
+ 25577777777777777777777777777552
54
+ 25777777777777777777777777777752
55
+ 27777777777777777777777777777772
56
+ 27777777777777777777777777777772
57
+ 27777777777777777777777777777772
58
+ 27777777777777888877777777777772
59
+ 27777777777777888877777777777772
60
+ 27777777777777777777777777777772
61
+ 27777777777777777777777777777772
62
+ 27777777777777777777777777777772
63
+ 25777777777777777777777777777752
64
+ 25577777777777777777777777777552
65
+ 25557777777777777777777777775552
66
+ 22222222222222222222222222222222
67
+ `, SpriteKind.Player)
68
+ info.setScore(mySprite.width)
69
+ ```
70
+
71
+ ## See also #seealso
72
+
73
+ [scale to percent](/reference/sprites/scaling/scale-to-percent)
74
+
75
+ ```package
76
+ sprite-scaling
77
+ ```
@@ -0,0 +1,144 @@
1
+ # scale by Pixels
2
+
3
+ Scale a sprite by a number of pixels in a direction from an anchor point.
4
+
5
+ ```sig
6
+ scaling.scaleByPixels(null, 1, ScaleDirection.Uniformly, ScaleAnchor.Middle)
7
+ ```
8
+
9
+ A sprite can scale to a number of pixels in a direction from an anchor point. The scaling can be in just in the direction chosen, or the sprite can scale proportionally in the other direction too.
10
+
11
+ ## Proportional scaling
12
+
13
+ If the scale direction is `vertically` or `horizontally` but **proportional** is set to `false`, the sprite will scale to the number of pixels given in **value** only in the chosen direction. The sprite will expand in height but the width will stay the same or the sprite will expand in width but the height will stat the same.
14
+
15
+ If the scaling direction is `vertically` and the `proportional` parameter is `true`, the width will also expand by the same ratio of change as the height. With this setting, expanding a `32` x `16` sprite in the vertical direction by `16` pixels will also expand the width by `32`. The same ratio scaling will happen for the height if the direction is `horizontally`.
16
+
17
+ ## Uniform scaling
18
+
19
+ When the scaling **direction** is set to `uniformly`, the sprite is scaled so that the new size will have both the width and height change by the same amount. If a sprite's current size is `64` x `16` and it's uniformly scaled by `64`, the new width is `128` and the new height is `80`.
20
+
21
+ ## Parameters
22
+
23
+ * **sprite**: the sprite to scale by a pixel amount.
24
+ * **value**: the [number](/types/number) of pixels to scale the sprite by.
25
+ * **direction**: the direction to scale in:
26
+ >* `horizontally`
27
+ >* `vertically`
28
+ >* `uniformly`
29
+ * **anchor**: an anchor point to scale the sprite from:
30
+ >* `middle`
31
+ >* `top`
32
+ >* `left`
33
+ >* `right`
34
+ >* `bottom`
35
+ >* `top left`
36
+ >* `top right`
37
+ >* `bottom right`
38
+ >* `bottom left`
39
+ * **proportional**: a [boolean](/types/boolean) value that when `true` will scale the sprite proportionally. If `false`, the sprite will only scale by **direction**. This parameter has no effect when **direction** is set to `uniformly`.
40
+
41
+ ## Example #example
42
+
43
+ ### Scaling tester #ex1
44
+
45
+ Make a program to test sprite scaling in both directions for expanding and shrinking. Use the controller buttons to increase and decrease the scale. Use buttons to turn **proportional** to `true` or `false`.
46
+
47
+ ```blocks
48
+ controller.up.onEvent(ControllerButtonEvent.Pressed, function () {
49
+ scaling.scaleByPixels(mySprite, pixelMin, ScaleDirection.Vertically, ScaleAnchor.Middle, proportion)
50
+ })
51
+ controller.B.onEvent(ControllerButtonEvent.Pressed, function () {
52
+ proportion = false
53
+ game.showLongText("Proportional = FALSE", DialogLayout.Bottom)
54
+ })
55
+ controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
56
+ proportion = true
57
+ game.showLongText("Proportional = TRUE", DialogLayout.Bottom)
58
+ })
59
+ controller.left.onEvent(ControllerButtonEvent.Pressed, function () {
60
+ if (mySprite.width > pixelMin) {
61
+ scaling.scaleByPixels(mySprite, pixelMin * -1, ScaleDirection.Horizontally, ScaleAnchor.Middle, proportion)
62
+ }
63
+ })
64
+ controller.right.onEvent(ControllerButtonEvent.Pressed, function () {
65
+ scaling.scaleByPixels(mySprite, pixelMin, ScaleDirection.Horizontally, ScaleAnchor.Middle, proportion)
66
+ })
67
+ controller.down.onEvent(ControllerButtonEvent.Pressed, function () {
68
+ if (mySprite.width > pixelMin) {
69
+ scaling.scaleByPixels(mySprite, pixelMin * -1, ScaleDirection.Vertically, ScaleAnchor.Middle, proportion)
70
+ }
71
+ })
72
+ let proportion = false
73
+ let pixelMin = 0
74
+ let mySprite: Sprite = null
75
+ mySprite = sprites.create(img`
76
+ 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
77
+ 2 5 5 5 7 7 7 7 7 7 7 7 5 5 5 2
78
+ 2 5 5 7 7 7 7 7 7 7 7 7 7 5 5 2
79
+ 2 5 7 7 7 7 7 7 7 7 7 7 7 7 5 2
80
+ 2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
81
+ 2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
82
+ 2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
83
+ 2 7 7 7 7 7 7 8 8 7 7 7 7 7 7 2
84
+ 2 7 7 7 7 7 7 8 8 7 7 7 7 7 7 2
85
+ 2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
86
+ 2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
87
+ 2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
88
+ 2 5 7 7 7 7 7 7 7 7 7 7 7 7 5 2
89
+ 2 5 5 7 7 7 7 7 7 7 7 7 7 5 5 2
90
+ 2 5 5 5 7 7 7 7 7 7 7 7 5 5 5 2
91
+ 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
92
+ `, SpriteKind.Player)
93
+ pixelMin = mySprite.width
94
+ let pixelMax = pixelMin * 5
95
+ game.showLongText("Proportional = FALSE", DialogLayout.Bottom)
96
+ ```
97
+
98
+ ### Uniformity tester #ex2
99
+
100
+ Test uniformly scaling a nonsquare sprite. Use the controller buttons to change the increased or decreased scale.
101
+
102
+ ```blocks
103
+ controller.up.onEvent(ControllerButtonEvent.Pressed, function () {
104
+ scaling.scaleByPixels(mySprite, pixelMax, ScaleDirection.Uniformly, ScaleAnchor.Middle)
105
+ info.setScore(mySprite.width)
106
+ })
107
+ controller.down.onEvent(ControllerButtonEvent.Pressed, function () {
108
+ if (my)
109
+ scaling.scaleByPixels(mySprite, pixelMin * -1, ScaleDirection.Uniformly, ScaleAnchor.Middle)
110
+ info.setScore(mySprite.width)
111
+ })
112
+ let pixelMax = 0
113
+ let pixelMin = 0
114
+ let mySprite: Sprite = null
115
+ mySprite = sprites.create(img`
116
+ 22222222222222222222222222222222
117
+ 25557777777777777777777777775552
118
+ 25577777777777777777777777777552
119
+ 25777777777777777777777777777752
120
+ 27777777777777777777777777777772
121
+ 27777777777777777777777777777772
122
+ 27777777777777777777777777777772
123
+ 27777777777777888877777777777772
124
+ 27777777777777888877777777777772
125
+ 27777777777777777777777777777772
126
+ 27777777777777777777777777777772
127
+ 27777777777777777777777777777772
128
+ 25777777777777777777777777777752
129
+ 25577777777777777777777777777552
130
+ 25557777777777777777777777775552
131
+ 22222222222222222222222222222222
132
+ `, SpriteKind.Player)
133
+ pixelMin = mySprite.height
134
+ pixelMax = pixelMin * 5
135
+ info.setScore(mySprite.width)
136
+ ```
137
+
138
+ ## See also #seealso
139
+
140
+ [scale by pixels](/reference/sprites/scaling/scale-by-pixels)
141
+
142
+ ```package
143
+ sprite-scaling
144
+ ```
@@ -0,0 +1,83 @@
1
+ # scale To Percent
2
+
3
+ Scale a sprite to a percentage of its original size in a direction from an anchor point.
4
+
5
+ ```sig
6
+ scaling.scaleToPercent(null, 100, ScaleDirection.Uniformly, ScaleAnchor.Middle)
7
+ ```
8
+
9
+ A sprite can scale to a percentage of its original size in a direction from an anchor point. The scaling can be in just one direction or the sprite can scale uniformly.
10
+
11
+ ## Uniform scaling
12
+
13
+ When the scaling **direction** is set to `uniformly`, the sprite is scaled so that the new size will have both the width and height changed by the same percentage **value**. If a sprite's original size is `64` x `32` and it's uniformly scaled to `50` percent, the new width is `32` and the new height is `16`.
14
+
15
+ ## Parameters
16
+
17
+ * **sprite**: the sprite to scale to a percentage of its original size.
18
+ * **value**: the [number](/types/number) that is the percentage to scale the sprite to.
19
+ * **direction**: the direction to scale in:
20
+ >* `horizontally`
21
+ >* `vertically`
22
+ >* `uniformly`
23
+ * **anchor**: an anchor point to scale the sprite from:
24
+ >* `middle`
25
+ >* `top`
26
+ >* `left`
27
+ >* `right`
28
+ >* `bottom`
29
+ >* `top left`
30
+ >* `top right`
31
+ >* `bottom right`
32
+ >* `bottom left`
33
+
34
+ ## Example #example
35
+
36
+ ### Scaling tester #ex1
37
+
38
+ Make a program to test sprite scaling in both directions for expanding and shrinking. Use the controller buttons to increase and decrease the scale to a percentage of the original sprite by direction. Use button `A` to set the pixel back to its original size.
39
+
40
+ ```blocks
41
+ controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
42
+ scaling.scaleToPercent(mySprite, 100, ScaleDirection.Uniformly, ScaleAnchor.Middle)
43
+ })
44
+ controller.up.onEvent(ControllerButtonEvent.Pressed, function () {
45
+ scaling.scaleToPercent(mySprite, 200, ScaleDirection.Vertically, ScaleAnchor.Middle)
46
+ })
47
+ controller.left.onEvent(ControllerButtonEvent.Pressed, function () {
48
+ scaling.scaleToPercent(mySprite, 50, ScaleDirection.Horizontally, ScaleAnchor.Middle)
49
+ })
50
+ controller.right.onEvent(ControllerButtonEvent.Pressed, function () {
51
+ scaling.scaleToPercent(mySprite, 200, ScaleDirection.Horizontally, ScaleAnchor.Middle)
52
+ })
53
+ controller.down.onEvent(ControllerButtonEvent.Pressed, function () {
54
+ scaling.scaleToPercent(mySprite, 50, ScaleDirection.Vertically, ScaleAnchor.Middle)
55
+ })
56
+ let mySprite: Sprite = null
57
+ mySprite = sprites.create(img`
58
+ 22222222222222222222222222222222
59
+ 25557777777777777777777777775552
60
+ 25577777777777777777777777777552
61
+ 25777777777777777777777777777752
62
+ 27777777777777777777777777777772
63
+ 27777777777777777777777777777772
64
+ 27777777777777777777777777777772
65
+ 27777777777777888877777777777772
66
+ 27777777777777888877777777777772
67
+ 27777777777777777777777777777772
68
+ 27777777777777777777777777777772
69
+ 27777777777777777777777777777772
70
+ 25777777777777777777777777777752
71
+ 25577777777777777777777777777552
72
+ 25557777777777777777777777775552
73
+ 22222222222222222222222222222222
74
+ `, SpriteKind.Player)
75
+ ```
76
+
77
+ ## See also #seealso
78
+
79
+ [scale by percent](/reference/sprites/scaling/scale-by-percent)
80
+
81
+ ```package
82
+ sprite-scaling
83
+ ```
@@ -0,0 +1,140 @@
1
+ # scale To Pixels
2
+
3
+ Scale a sprite to a number of pixels in a direction from an anchor point.
4
+
5
+ ```sig
6
+ scaling.scaleToPixels(null, 1, ScaleDirection.Uniformly, ScaleAnchor.Middle)
7
+ ```
8
+
9
+ A sprite can scale to a number of pixels in a direction from an anchor point. The scaling can be in just in the direction chosen, or the sprite can scale proportionally in the other direction too.
10
+
11
+ ## Proportional scaling
12
+
13
+ If the scale direction is `vertically` or `horizontally` but **proportional** is set to `false`, the sprite will scale to the number of pixels given in **value** only in the chosen direction. The sprite will expand in height but the width will stay the same or the sprite will expand in width but the height will stat the same.
14
+
15
+ If the scaling direction is `vertically` and the `proportional` parameter is `true`, the width will also expand by the same ratio of change as the height. With this setting, expanding a `32` x `16` sprite in the vertical direction to `32` pixels will also expand the width to `64`. The same ratio scaling will happen for the height if the direction is `horizontally`.
16
+
17
+ ## Uniform scaling
18
+
19
+ When the scaling **direction** is set to `uniformly`, the sprite is scaled so that te new size will have both the width and height the same. If a sprite's current size is `64` x `16` and it's uniformly scaled to `128`, the new width and height will both be `128`.
20
+
21
+ ## Parameters
22
+
23
+ * **sprite**: the sprite to scale to a pixel amount.
24
+ * **value**: the [number](/types/number) of pixels to scale the sprite to.
25
+ * **direction**: the direction to scale in:
26
+ >* `horizontally`
27
+ >* `vertically`
28
+ >* `uniformly`
29
+ * **anchor**: an anchor point to scale the sprite from:
30
+ >* `middle`
31
+ >* `top`
32
+ >* `left`
33
+ >* `right`
34
+ >* `bottom`
35
+ >* `top left`
36
+ >* `top right`
37
+ >* `bottom right`
38
+ >* `bottom left`
39
+ * **proportional**: a [boolean](/types/boolean) value that when `true` will scale the sprite proportionally. If `false`, the sprite will only scale by **direction**. This parameter has no effect when **direction** is set to `uniformly`.
40
+
41
+ ## Example #example
42
+
43
+ ### Scaling tester #ex1
44
+
45
+ Make a program to test sprite scaling in both directions for expanding and shrinking. Use the controller buttons to increase and decrease the scale. Use buttons to turn **proportional** to `true` or `false`.
46
+
47
+ ```blocks
48
+ controller.B.onEvent(ControllerButtonEvent.Pressed, function () {
49
+ proportion = false
50
+ game.showLongText("Proportional = FALSE", DialogLayout.Bottom)
51
+ })
52
+ controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
53
+ proportion = true
54
+ game.showLongText("Proportional = TRUE", DialogLayout.Bottom)
55
+ })
56
+ controller.left.onEvent(ControllerButtonEvent.Pressed, function () {
57
+ scaling.scaleToPixels(mySprite, pixelMin, ScaleDirection.Horizontally, ScaleAnchor.Middle, proportion)
58
+ })
59
+ controller.right.onEvent(ControllerButtonEvent.Pressed, function () {
60
+ scaling.scaleToPixels(mySprite, pixelMax, ScaleDirection.Horizontally, ScaleAnchor.Middle, proportion)
61
+ })
62
+ controller.up.onEvent(ControllerButtonEvent.Pressed, function () {
63
+ scaling.scaleToPixels(mySprite, pixelMax, ScaleDirection.Vertically, ScaleAnchor.Middle, proportion)
64
+ })
65
+ controller.down.onEvent(ControllerButtonEvent.Pressed, function () {
66
+ scaling.scaleToPixels(mySprite, pixelMin, ScaleDirection.Vertically, ScaleAnchor.Middle, proportion)
67
+ })
68
+ let proportion = false
69
+ let pixelMax = 0
70
+ let pixelMin = 0
71
+ let mySprite: Sprite = null
72
+ mySprite = sprites.create(img`
73
+ 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
74
+ 2 5 5 5 7 7 7 7 7 7 7 7 5 5 5 2
75
+ 2 5 5 7 7 7 7 7 7 7 7 7 7 5 5 2
76
+ 2 5 7 7 7 7 7 7 7 7 7 7 7 7 5 2
77
+ 2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
78
+ 2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
79
+ 2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
80
+ 2 7 7 7 7 7 7 8 8 7 7 7 7 7 7 2
81
+ 2 7 7 7 7 7 7 8 8 7 7 7 7 7 7 2
82
+ 2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
83
+ 2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
84
+ 2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 2
85
+ 2 5 7 7 7 7 7 7 7 7 7 7 7 7 5 2
86
+ 2 5 5 7 7 7 7 7 7 7 7 7 7 5 5 2
87
+ 2 5 5 5 7 7 7 7 7 7 7 7 5 5 5 2
88
+ 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
89
+ `, SpriteKind.Player)
90
+ pixelMin = mySprite.width
91
+ pixelMax = pixelMin * 5
92
+ game.showLongText("Proportional = FALSE", DialogLayout.Bottom)
93
+ ```
94
+
95
+ ### Uniformity tester #ex2
96
+
97
+ Test uniformly scaling a nonsquare sprite. Use the `up` and `down` controller buttons to increase and decrease the scale.
98
+
99
+ ```blocks
100
+ controller.up.onEvent(ControllerButtonEvent.Pressed, function () {
101
+ scaling.scaleToPixels(mySprite, pixelMax, ScaleDirection.Uniformly, ScaleAnchor.Middle)
102
+ info.setScore(mySprite.width)
103
+ })
104
+ controller.down.onEvent(ControllerButtonEvent.Pressed, function () {
105
+ scaling.scaleToPixels(mySprite, pixelMin, ScaleDirection.Uniformly, ScaleAnchor.Middle)
106
+ info.setScore(mySprite.width)
107
+ })
108
+ let pixelMax = 0
109
+ let pixelMin = 0
110
+ let mySprite: Sprite = null
111
+ mySprite = sprites.create(img`
112
+ 22222222222222222222222222222222
113
+ 25557777777777777777777777775552
114
+ 25577777777777777777777777777552
115
+ 25777777777777777777777777777752
116
+ 27777777777777777777777777777772
117
+ 27777777777777777777777777777772
118
+ 27777777777777777777777777777772
119
+ 27777777777777888877777777777772
120
+ 27777777777777888877777777777772
121
+ 27777777777777777777777777777772
122
+ 27777777777777777777777777777772
123
+ 27777777777777777777777777777772
124
+ 25777777777777777777777777777752
125
+ 25577777777777777777777777777552
126
+ 25557777777777777777777777775552
127
+ 22222222222222222222222222222222
128
+ `, SpriteKind.Player)
129
+ pixelMin = mySprite.height
130
+ pixelMax = pixelMin * 5
131
+ info.setScore(mySprite.width)
132
+ ```
133
+
134
+ ## See also #seealso
135
+
136
+ [scale by pixels](/reference/sprites/scaling/scale-to-pixels)
137
+
138
+ ```package
139
+ sprite-scaling
140
+ ```
@@ -1,15 +1,15 @@
1
- namespace sprites {
2
- //% blockId=sprite_set_scale_ex
3
- //% block="set $sprite=variables_get(mySprite) scale to $value || $direction anchor $anchor"
4
- //% advanced=true
1
+ //% color="#95078E" weight=99 icon="\uf338"
2
+ namespace scaling {
3
+ //% blockId=sprite_scale_to_percent_ex
4
+ //% block="set $sprite=variables_get(mySprite) scale to $value percent $direction anchor $anchor"
5
5
  //% expandableArgumentMode=enabled
6
6
  //% inlineInputMode=inline
7
- //% value.defl=1
7
+ //% value.defl=150
8
8
  //% direction.defl=ScaleDirection.Uniformly
9
9
  //% anchor.defl=ScaleAnchor.Middle
10
- //% help=sprites/sprite-scaling/set-scale
11
- //% group="Scale" weight=90
12
- export function setScale(sprite: Sprite, value: number, direction?: ScaleDirection, anchor?: ScaleAnchor): void {
10
+ //% help=sprites/scaling/scale-to-percent
11
+ export function scaleToPercent(sprite: Sprite, value: number, direction?: ScaleDirection, anchor?: ScaleAnchor): void {
12
+ value /= 100;
13
13
  direction = direction || ScaleDirection.Uniformly;
14
14
  anchor = anchor || ScaleAnchor.Middle;
15
15
 
@@ -22,90 +22,91 @@ namespace sprites {
22
22
  sprite.setScaleCore(sx, sy, anchor);
23
23
  }
24
24
 
25
- //% blockId=sprite_grow_by_percent_ex
26
- //% block="grow $sprite=variables_get(mySprite) by $amount percent || $direction anchor $anchor"
27
- //% advanced=true
25
+ //% blockId=sprite_scale_by_percent_ex
26
+ //% block="change $sprite=variables_get(mySprite) scale by $value percent $direction anchor $anchor"
28
27
  //% expandableArgumentMode=enabled
29
28
  //% inlineInputMode=inline
30
- //% amount.defl=10
29
+ //% value.defl=50
31
30
  //% direction.defl=ScaleDirection.Uniformly
32
31
  //% anchor.defl=ScaleAnchor.Middle
33
- //% help=sprites/sprite-scaling/grow-by-amount
34
- //% group="Scale" weight=80
35
- export function growByPercent(sprite: Sprite, amount: number, direction?: ScaleDirection, anchor?: ScaleAnchor): void {
36
- amount /= 100;
32
+ //% help=sprites/scaling/scale-by-percent
33
+ export function scaleByPercent(sprite: Sprite, value: number, direction?: ScaleDirection, anchor?: ScaleAnchor): void {
34
+ value /= 100;
37
35
  direction = direction || ScaleDirection.Uniformly;
38
36
  anchor = anchor || ScaleAnchor.Middle;
39
37
 
40
38
  let sx: number;
41
39
  let sy: number;
42
40
 
43
- if (direction & ScaleDirection.Horizontally) sx = sprite.sx + amount;
44
- if (direction & ScaleDirection.Vertically) sy = sprite.sy + amount;
41
+ if (direction & ScaleDirection.Horizontally) sx = sprite.sx + value;
42
+ if (direction & ScaleDirection.Vertically) sy = sprite.sy + value;
45
43
 
46
44
  sprite.setScaleCore(sx, sy, anchor);
47
45
  }
48
46
 
49
- //% blockId=sprite_shrink_by_percent_ex
50
- //% block="shrink $sprite=variables_get(mySprite) by $amount percent || $direction anchor $anchor"
51
- //% advanced=true
47
+ //% blockId=sprite_scale_to_pixels_ex
48
+ //% block="set $sprite=variables_get(mySprite) scale to $value pixels $direction anchor $anchor || proportional $proportional"
52
49
  //% expandableArgumentMode=enabled
53
50
  //% inlineInputMode=inline
54
- //% amount.defl=10
55
- //% direction.defl=ScaleDirection.Uniformly
56
- //% anchor.defl=ScaleAnchor.Middle
57
- //% help=sprites/sprite-scaling/shrink-by-percent
58
- //% group="Scale" weight=70
59
- export function shrinkByPercent(sprite: Sprite, amount: number, direction?: ScaleDirection, anchor?: ScaleAnchor): void {
60
- growByPercent(sprite, -amount, direction, anchor);
61
- }
62
-
63
- //% blockId=sprite_grow_by_pixels_ex
64
- //% block="grow $sprite=variables_get(mySprite) by $amount pixels $direction || anchor $anchor proportional $proportional"
65
- //% advanced=true
66
- //% expandableArgumentMode=enabled
67
- //% inlineInputMode=inline
68
- //% amount.defl=10
51
+ //% value.defl=32
69
52
  //% direction.defl=ScaleDirection.Horizontally
70
53
  //% anchor.defl=ScaleAnchor.Middle
71
54
  //% proportional.defl=0
72
- //% help=sprites/sprite-scaling/grow-by-pixels
73
- //% group="Scale" weight=60
74
- export function growByPixels(sprite: Sprite, amount: number, direction?: ScaleDirection, anchor?: ScaleAnchor, proportional?: boolean): void {
55
+ //% help=sprites/scaling/scale-to-pixels
56
+ export function scaleToPixels(sprite: Sprite, value: number, direction?: ScaleDirection, anchor?: ScaleAnchor, proportional?: boolean): void {
75
57
  direction = direction || ScaleDirection.Horizontally;
76
58
  anchor = anchor || ScaleAnchor.Middle;
77
- if (typeof proportional !== 'boolean') proportional = direction === ScaleDirection.Uniformly;
59
+
60
+ if (proportional == null) proportional = direction === ScaleDirection.Uniformly;
78
61
 
79
62
  let sx: number;
80
63
  let sy: number;
81
64
 
82
65
  if (direction & ScaleDirection.Horizontally) {
83
66
  const imgW = sprite.image.width;
84
- const newW = sprite.width + amount;
67
+ const newW = value;
85
68
  sx = newW / imgW;
86
69
  }
87
70
 
88
71
  if (direction & ScaleDirection.Vertically) {
89
72
  const imgH = sprite.image.height;
90
- const newH = sprite.height + amount;
73
+ const newH = value;
91
74
  sy = newH / imgH;
92
75
  }
93
76
 
94
77
  sprite.setScaleCore(sx, sy, anchor, proportional);
95
78
  }
96
79
 
97
- //% blockId=sprite_shrink_by_pixels
98
- //% block="shrink $sprite=variables_get(mySprite) by $amount pixels $direction || anchor $anchor proportional $proportional"
99
- //% advanced=true
80
+ //% blockId=sprite_scale_by_pixels_ex
81
+ //% block="change $sprite=variables_get(mySprite) scale by $value pixels $direction anchor $anchor || proportional $proportional"
100
82
  //% expandableArgumentMode=enabled
101
83
  //% inlineInputMode=inline
102
- //% amount.defl=10
84
+ //% value.defl=10
103
85
  //% direction.defl=ScaleDirection.Horizontally
104
86
  //% anchor.defl=ScaleAnchor.Middle
105
87
  //% proportional.defl=0
106
- //% help=sprites/sprite-scaling/grow-by-pixels
107
- //% group="Scale" weight=50
108
- export function shrinkByPixels(sprite: Sprite, amount: number, direction?: ScaleDirection, anchor?: ScaleAnchor, proportional?: boolean): void {
109
- growByPixels(sprite, -amount, direction, anchor, proportional);
88
+ //% help=sprites/scaling/scale-by-pixels
89
+ export function scaleByPixels(sprite: Sprite, value: number, direction?: ScaleDirection, anchor?: ScaleAnchor, proportional?: boolean): void {
90
+ direction = direction || ScaleDirection.Horizontally;
91
+ anchor = anchor || ScaleAnchor.Middle;
92
+
93
+ if (proportional == null) proportional = direction === ScaleDirection.Uniformly;
94
+
95
+ let sx: number;
96
+ let sy: number;
97
+
98
+ if (direction & ScaleDirection.Horizontally) {
99
+ const imgW = sprite.image.width;
100
+ const newW = sprite.width + value;
101
+ sx = newW / imgW;
102
+ }
103
+
104
+ if (direction & ScaleDirection.Vertically) {
105
+ const imgH = sprite.image.height;
106
+ const newH = sprite.height + value;
107
+ sy = newH / imgH;
108
+ }
109
+
110
+ sprite.setScaleCore(sx, sy, anchor, proportional);
110
111
  }
111
112
  }