litecanvas 0.98.3 → 0.98.4
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/README.md +92 -0
- package/dist/dist.dev.js +3 -3
- package/package.json +1 -1
- package/src/index.js +2 -3
- package/src/version.js +1 -1
package/README.md
CHANGED
|
@@ -151,6 +151,98 @@ function draw() {
|
|
|
151
151
|
}
|
|
152
152
|
```
|
|
153
153
|
|
|
154
|
+
### Drawing sprites
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
litecanvas({
|
|
158
|
+
width: 128
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
// you can create sprites with strings
|
|
162
|
+
// each visible char is a pixel
|
|
163
|
+
// numbers are colors
|
|
164
|
+
// dots are transparent pixels
|
|
165
|
+
const smile = `
|
|
166
|
+
.555555.
|
|
167
|
+
55555555
|
|
168
|
+
55055055
|
|
169
|
+
55055055
|
|
170
|
+
55555555
|
|
171
|
+
50555505
|
|
172
|
+
55000055
|
|
173
|
+
.555555.`
|
|
174
|
+
|
|
175
|
+
function draw() {
|
|
176
|
+
cls(0)
|
|
177
|
+
|
|
178
|
+
spr(
|
|
179
|
+
0, 0, // position X Y
|
|
180
|
+
8, 8, // sprite Width and Height
|
|
181
|
+
smile // the pixels
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Creating and drawing images
|
|
187
|
+
|
|
188
|
+
```js
|
|
189
|
+
litecanvas()
|
|
190
|
+
|
|
191
|
+
// lets create the flag of the Japan
|
|
192
|
+
const japan = paint(
|
|
193
|
+
48, 32, // image width and height
|
|
194
|
+
function () {
|
|
195
|
+
// the result of this drawings
|
|
196
|
+
// goes to an offscreen canvas
|
|
197
|
+
rectfill(0, 0, 48, 32, 3)
|
|
198
|
+
circfill(24, 16, 8, 4)
|
|
199
|
+
}, {
|
|
200
|
+
// you can scale your image
|
|
201
|
+
// by default, scale=1
|
|
202
|
+
scale: 4
|
|
203
|
+
}
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
function draw() {
|
|
207
|
+
cls(0)
|
|
208
|
+
// now the japan variable holds a image
|
|
209
|
+
image(W/2 - japan.width/2, H/2 - japan.height/2, japan)
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
It's very useful when you need to draw something the same way every time. This way, you create an image of that drawing, working as a kind of cache.
|
|
214
|
+
|
|
215
|
+
You can also use the image() function to draw PNG/JPG images, but you'll need to load them first:
|
|
216
|
+
|
|
217
|
+
```js
|
|
218
|
+
litecanvas()
|
|
219
|
+
|
|
220
|
+
let PngImage
|
|
221
|
+
|
|
222
|
+
function init() {
|
|
223
|
+
// load a image from its URL
|
|
224
|
+
const img = new Image()
|
|
225
|
+
img.onload = () => {
|
|
226
|
+
PngImage = img
|
|
227
|
+
}
|
|
228
|
+
img.src = 'https://litecanvas.js.org/icons/icon-128.png'
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function draw() {
|
|
232
|
+
cls(0)
|
|
233
|
+
|
|
234
|
+
if (!PngImage) {
|
|
235
|
+
// if not loaded, show this message
|
|
236
|
+
text(10, 10, 'Loading image...')
|
|
237
|
+
} else {
|
|
238
|
+
// when loaded, draw the image file
|
|
239
|
+
image(0, 0, PngImage)
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
To help you load multiple assets (images, fonts, music, etc.), you can I recommend you the [Asset Loader Plugin](https://github.com/litecanvas/plugin-asset-loader).
|
|
245
|
+
|
|
154
246
|
### Keyboard
|
|
155
247
|
|
|
156
248
|
```js
|
package/dist/dist.dev.js
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
// src/version.js
|
|
35
|
-
var version = "0.98.
|
|
35
|
+
var version = "0.98.4";
|
|
36
36
|
|
|
37
37
|
// src/index.js
|
|
38
38
|
function litecanvas(settings = {}) {
|
|
@@ -283,8 +283,8 @@
|
|
|
283
283
|
*/
|
|
284
284
|
rseed(value) {
|
|
285
285
|
DEV: assert(
|
|
286
|
-
|
|
287
|
-
"[litecanvas] rseed() 1st param must be a positive
|
|
286
|
+
isNumber(value) && value >= 0,
|
|
287
|
+
"[litecanvas] rseed() 1st param must be a positive integer or zero"
|
|
288
288
|
);
|
|
289
289
|
_rngSeed = ~~value;
|
|
290
290
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "litecanvas",
|
|
3
|
-
"version": "0.98.
|
|
3
|
+
"version": "0.98.4",
|
|
4
4
|
"description": "Lightweight HTML5 canvas 2D game engine suitable for small projects and creative coding. Inspired by PICO-8 and p5.js/Processing.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Luiz Bills <luizbills@pm.me>",
|
package/src/index.js
CHANGED
|
@@ -351,10 +351,9 @@ export default function litecanvas(settings = {}) {
|
|
|
351
351
|
*/
|
|
352
352
|
rseed(value) {
|
|
353
353
|
DEV: assert(
|
|
354
|
-
|
|
355
|
-
'[litecanvas] rseed() 1st param must be a positive
|
|
354
|
+
isNumber(value) && value >= 0,
|
|
355
|
+
'[litecanvas] rseed() 1st param must be a positive integer or zero'
|
|
356
356
|
)
|
|
357
|
-
|
|
358
357
|
_rngSeed = ~~value
|
|
359
358
|
},
|
|
360
359
|
|
package/src/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '0.98.
|
|
2
|
+
export const version = '0.98.4'
|