littlejsengine 1.13.4 → 1.14.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/README.md +2 -1
- package/copyToGithub.bat +28 -0
- package/dist/littlejs.d.ts +346 -240
- package/dist/littlejs.esm.js +1370 -723
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +1350 -709
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +1333 -692
- package/examples/box2d/game.js +1 -1
- package/examples/box2d/gameObjects.js +1 -1
- package/examples/breakout/game.js +30 -25
- package/examples/electron/index.html +2 -2
- package/examples/index.html +207 -96
- package/examples/platformer/gameEffects.js +19 -18
- package/examples/platformer/gameLevel.js +6 -1
- package/examples/shorts/base.html +1 -1
- package/examples/shorts/flappyGame.js +2 -1
- package/examples/shorts/helloWorld.js +1 -1
- package/examples/shorts/music.js +106 -0
- package/examples/shorts/parallax.js +71 -0
- package/examples/shorts/piano.js +7 -8
- package/examples/shorts/postProcess.js +25 -8
- package/examples/shorts/shapes.js +1 -9
- package/examples/shorts/song.mp3 +0 -0
- package/examples/shorts/uiSystem.js +15 -8
- package/examples/starter/index.html +2 -2
- package/examples/stress/index.html +8 -3
- package/examples/style.css +14 -4
- package/examples/uiSystem/game.js +11 -11
- package/package.json +1 -1
- package/plugins/box2d.js +10 -8
- package/plugins/drawUtilities.js +5 -5
- package/plugins/newgrounds.js +6 -6
- package/plugins/pluginExport.js +1 -1
- package/plugins/uiSystem.js +103 -79
- package/plugins/zzfxm.js +10 -10
- package/reference.md +90 -54
- package/src/engine.js +22 -22
- package/src/engineAudio.js +284 -109
- package/src/engineBuild.js +9 -9
- package/src/engineDebug.js +26 -26
- package/src/engineDraw.js +148 -97
- package/src/engineExport.js +22 -16
- package/src/engineInput.js +57 -67
- package/src/engineMedals.js +25 -25
- package/src/engineObject.js +25 -22
- package/src/engineParticles.js +59 -59
- package/src/engineRelease.js +1 -1
- package/src/engineSettings.js +20 -13
- package/src/engineTileLayer.js +34 -34
- package/src/engineUtilities.js +62 -55
- package/src/engineWebGL.js +447 -65
- /package/examples/shorts/{playSound.js → sound.js} +0 -0
package/reference.md
CHANGED
|
@@ -33,13 +33,14 @@ tile(pos, size=(16,16), texture=0, padding=0) // Create a tile info object
|
|
|
33
33
|
|
|
34
34
|
// Helper functions
|
|
35
35
|
abs(value) // Get absolute value
|
|
36
|
-
min(
|
|
37
|
-
max(
|
|
36
|
+
min(...values) // Get lowest of values
|
|
37
|
+
max(...values) // Get highest of values
|
|
38
38
|
sign(value) // Get the sign of value
|
|
39
39
|
mod(dividend, divisor=1) // Get remainder of division
|
|
40
40
|
clamp(value, min=0, max=1) // Clamps between values
|
|
41
41
|
percent(value, valueA, valueB) // Get percentage between values
|
|
42
42
|
lerp(valueA, valueB, percent) // Linearly interpolates between values
|
|
43
|
+
percentLerp(value, percentA, percentB, lerpA, lerpB) // Lerp that remaps the percent
|
|
43
44
|
distanceWrap(valueA, valueB, wrapSize=1) // Signed wrapped distance between values
|
|
44
45
|
lerpWrap(valueA, valueB, percent, wrapSize=1) // Linearly interpolates with wrapping
|
|
45
46
|
distanceAngle(angleA, angleB) // Signed wrapped distance between angles
|
|
@@ -54,7 +55,8 @@ formatTime(t) // Formats seconds for display
|
|
|
54
55
|
// Random functions
|
|
55
56
|
rand(valueA=1, valueB=0) // Random float between values
|
|
56
57
|
randInt(valueA, valueB=0) // Random integer between values
|
|
57
|
-
|
|
58
|
+
randBool(chance=.5) // Random boolean with given chance (0 to 1)
|
|
59
|
+
randSign() // Randomly either -1 or 1
|
|
58
60
|
randVec2(length=1) // Random Vector2 with the passed in length
|
|
59
61
|
randInCircle(radius=1, minRadius=0) // Random Vector2 within a circle
|
|
60
62
|
randColor(colorA, colorB, linear) // Random color between values
|
|
@@ -111,16 +113,16 @@ RandomGenerator.int(valueA, valueB=0) // Random integer between values
|
|
|
111
113
|
RandomGenerator.sign() // Randomly either -1 or 1
|
|
112
114
|
|
|
113
115
|
// Time tracking system
|
|
114
|
-
Timer(timeLeft)
|
|
115
|
-
Timer.set(timeLeft=0)
|
|
116
|
-
Timer.unset()
|
|
117
|
-
Timer.isSet()
|
|
118
|
-
Timer.active()
|
|
119
|
-
Timer.elapsed()
|
|
120
|
-
Timer.get()
|
|
121
|
-
Timer.getPercent()
|
|
122
|
-
Timer.toString()
|
|
123
|
-
Timer.valueOf()
|
|
116
|
+
Timer(timeLeft) // Create a timer object
|
|
117
|
+
Timer.set(timeLeft=0) // Set the timer with seconds passed in
|
|
118
|
+
Timer.unset() // Unset the timer
|
|
119
|
+
Timer.isSet() // Returns true if set
|
|
120
|
+
Timer.active() // Returns true if set and has not elapsed
|
|
121
|
+
Timer.elapsed() // Returns true if set and elapsed
|
|
122
|
+
Timer.get() // Get how long since elapsed, 0 if not set
|
|
123
|
+
Timer.getPercent() // Get percent elapsed, 0 if not set
|
|
124
|
+
Timer.toString() // Get this timer expressed as a string
|
|
125
|
+
Timer.valueOf() // Get how long since elapsed, 0 if not set
|
|
124
126
|
```
|
|
125
127
|
|
|
126
128
|
## LittleJS Drawing System
|
|
@@ -131,35 +133,46 @@ Timer.valueOf() // Get how long since elapsed, 0 if not set
|
|
|
131
133
|
|
|
132
134
|
```javascript
|
|
133
135
|
// Drawing functions
|
|
134
|
-
drawTile(pos, size
|
|
135
|
-
drawRect(pos, size
|
|
136
|
-
drawLine(posA, posB, thickness=.1, color=WHITE)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
drawTile(pos, size, tileInfo, color=WHITE, angle=0, mirror, additiveColor)
|
|
137
|
+
drawRect(pos, size, color=WHITE, angle=0)
|
|
138
|
+
drawLine(posA, posB, thickness=.1, color=WHITE, pos=(0,0), angle=0)
|
|
139
|
+
drawPoly(points, color=WHITE, lineWidth=0, lineColor=BLACK, pos, angle=0)
|
|
140
|
+
drawRegularPoly(pos, size=(1,1), sides=3, color=WHITE)
|
|
141
|
+
drawEllipse(pos, size, color=WHITE, angle=0, lineWidth=0, lineColor=BLACK)
|
|
142
|
+
drawCircle(pos, radius=1, color=WHITE, lineWidth=0, lineColor=BLACK)
|
|
143
|
+
drawCanvas2D(pos, size, angle=0, mirror, drawFunction, screenSpace, context)
|
|
144
|
+
|
|
145
|
+
// Text functions
|
|
146
|
+
drawText(text, pos, size=1, color=WHITE, lineWidth=0, lineColor=BLACK)
|
|
147
|
+
drawTextOverlay(text, pos, size=1, color=WHITE, lineWidth=0, lineColor=BLACK)
|
|
148
|
+
drawTextScreen(text, pos, size=1, color=WHITE, lineWidth=0, lineColor=BLACK)
|
|
149
|
+
|
|
150
|
+
// Utility drawing functions
|
|
140
151
|
setBlendMode(additive)
|
|
141
|
-
toggleFullscreen()
|
|
142
152
|
isFullscreen()
|
|
153
|
+
toggleFullscreen()
|
|
143
154
|
|
|
144
155
|
// Tile Info Object
|
|
145
|
-
TileInfo(pos
|
|
146
|
-
TileInfo.pos
|
|
147
|
-
TileInfo.size
|
|
148
|
-
TileInfo.textureIndex
|
|
149
|
-
TileInfo.
|
|
150
|
-
TileInfo.
|
|
151
|
-
TileInfo.
|
|
156
|
+
TileInfo(pos, size, textureIndex=0, padding=0) // Create a tile info object
|
|
157
|
+
TileInfo.pos // Top left corner of tile in pixels
|
|
158
|
+
TileInfo.size // Size of tile in pixels
|
|
159
|
+
TileInfo.textureIndex // Texture index to use
|
|
160
|
+
TileInfo.padding // How many pixels padding around tiles
|
|
161
|
+
TileInfo.offset(offset) // Offset this tile by a certain amount in pixels
|
|
162
|
+
TileInfo.frame(frame) // Offset this tile by a number of animation frames
|
|
163
|
+
TileInfo.textureInfo // The texture info for this tile
|
|
152
164
|
|
|
153
165
|
// Texture Info Object
|
|
154
|
-
TextureInfo(image)
|
|
155
|
-
TextureInfo.image
|
|
156
|
-
TextureInfo.size
|
|
157
|
-
TextureInfo.glTexture
|
|
166
|
+
TextureInfo(image) // Created automatically for each image
|
|
167
|
+
TextureInfo.image // Image source
|
|
168
|
+
TextureInfo.size // Size of the image
|
|
169
|
+
TextureInfo.glTexture // WebGL texture
|
|
158
170
|
|
|
159
171
|
// Font Image Object draws text using characters in an image
|
|
160
172
|
FontImage(image, tileSize=(8,8), paddingSize=(0,1)) // Create an image font
|
|
161
173
|
FontImage.drawText(text, pos, scale, center) // Draw text in world space
|
|
162
174
|
FontImage.drawTextScreen(text, pos, scale, center) // Draw text in screen space
|
|
175
|
+
FontImage.drawTextOverlay(text, pos, scale, center) // Draw text to overlay canvas
|
|
163
176
|
|
|
164
177
|
// Camera settings
|
|
165
178
|
cameraPos = (0,0) // Position of camera in world space
|
|
@@ -183,31 +196,45 @@ tileFixBleedScale = .3 // How much smaller to draw tiles to prevent bleeding
|
|
|
183
196
|
```
|
|
184
197
|
|
|
185
198
|
## LittleJS Audio System
|
|
186
|
-
- Caches sounds and music for fast playback
|
|
199
|
+
- Caches sounds and music for fast playback with frame-spread loading
|
|
200
|
+
- Individual sound instance control with pause/resume capabilities
|
|
187
201
|
- Can attenuate and apply stereo panning to sounds
|
|
188
|
-
- Ability to play mp3, ogg, and wave
|
|
202
|
+
- Ability to play mp3, ogg, and wave files with loading progress tracking
|
|
189
203
|
- [ZzFX Sound Effect Generator](https://killedbyapixel.github.io/ZzFX)
|
|
190
204
|
- [ZzFXM Music System](https://keithclark.github.io/ZzFXM)
|
|
191
205
|
|
|
192
206
|
```javascript
|
|
193
207
|
// Sound Object
|
|
194
|
-
Sound(zzfxSound)
|
|
195
|
-
SoundWave(filename, randomness=0)
|
|
196
|
-
Sound.play(pos, volume=1, pitch=1, randomness=1, loop)
|
|
197
|
-
Sound.
|
|
198
|
-
Sound.
|
|
199
|
-
Sound.
|
|
200
|
-
Sound.
|
|
201
|
-
Sound.
|
|
202
|
-
|
|
203
|
-
//
|
|
204
|
-
|
|
205
|
-
|
|
208
|
+
Sound(zzfxSound, range, taper) // Create a zzfx sound
|
|
209
|
+
SoundWave(filename, randomness=0, range, taper) // Load a wave, mp3, or ogg
|
|
210
|
+
Sound.play(pos, volume=1, pitch=1, randomness=1, loop) // Play a sound, returns SoundInstance
|
|
211
|
+
Sound.playMusic(volume=1, loop=true) // Play as music with looping
|
|
212
|
+
Sound.playNote(semitoneOffset, pos, volume=1) // Play as note with a semitone offset
|
|
213
|
+
Sound.getDuration() // Get length of sound in seconds
|
|
214
|
+
Sound.isLoaded() // Check if sound is currently loading
|
|
215
|
+
Sound.loadedPercent // Get loading progress (0 to 1)
|
|
216
|
+
|
|
217
|
+
// SoundInstance
|
|
218
|
+
SoundInstance.start() // Start playing the sound
|
|
219
|
+
SoundInstance.setVolume(volume) // Change volume during playback
|
|
220
|
+
SoundInstance.stop(fadeTime=0) // Stop with optional fade out
|
|
221
|
+
SoundInstance.pause() // Pause the sound
|
|
222
|
+
SoundInstance.unpause() // Resume paused sound
|
|
223
|
+
SoundInstance.isPlaying() // Check if currently playing
|
|
224
|
+
SoundInstance.isPaused() // Check if paused
|
|
225
|
+
SoundInstance.isStopped() // Check if stopped
|
|
226
|
+
SoundInstance.getCurrentTime() // Get current playback position
|
|
227
|
+
SoundInstance.getDuration() // Get total duration
|
|
228
|
+
SoundInstance.getSource() // Get AudioBufferSourceNode
|
|
229
|
+
|
|
230
|
+
// ZzFXM - Tiny music playing system
|
|
231
|
+
Music(..zzfxMusic) // Create a zzfx music object
|
|
232
|
+
Music.playMusic(volume=1, loop=true) // Play the music
|
|
206
233
|
|
|
207
234
|
// Audio functions
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
235
|
+
speak(text, language='', volume=1, rate=1, pitch=1) // Speak text line
|
|
236
|
+
speakStop() // Stop all queued speech
|
|
237
|
+
getNoteFrequency(semitoneOffset, rootFrequency=220) // Get frequency for musical notes
|
|
211
238
|
|
|
212
239
|
// Audio settings
|
|
213
240
|
soundEnable = true // Should sound be enabled?
|
|
@@ -228,11 +255,13 @@ soundDefaultTaper = .7 // Default range percent to taper off sound (0-1)
|
|
|
228
255
|
keyIsDown(key) // Is key down?
|
|
229
256
|
keyWasPressed(key) // Was key pressed this frame?
|
|
230
257
|
keyWasReleased(key) // Was key released this frame?
|
|
231
|
-
keyDirection(up, down, left, right)
|
|
258
|
+
keyDirection(up, down, left, right) // Get input vector from arrow keys or wasd
|
|
232
259
|
|
|
233
260
|
// Mouse / Touch
|
|
234
261
|
mousePos // World space mouse position
|
|
235
262
|
mousePosScreen // Screen space mouse position
|
|
263
|
+
mouseDelta // World space mouse movement delta
|
|
264
|
+
mouseDeltaScreen // Screen space mouse movement delta
|
|
236
265
|
mouseWheel // Delta mouse wheel this frame
|
|
237
266
|
mouseIsDown(button) // Is mouse button down?
|
|
238
267
|
mouseWasPressed(button) // Was mouse button pressed this frame?
|
|
@@ -286,7 +315,7 @@ EngineObject.render() // Render object, called auto
|
|
|
286
315
|
EngineObject.destroy() // Destroy this object and children
|
|
287
316
|
EngineObject.collideWithTile(tileData, pos) // Tile collision resolve check
|
|
288
317
|
EngineObject.collideWithObject(object) // Object collision resolve check
|
|
289
|
-
EngineObject.getAliveTime(
|
|
318
|
+
EngineObject.getAliveTime() // How long since object was created
|
|
290
319
|
EngineObject.applyAcceleration(acceleration) // Apply acceleration
|
|
291
320
|
EngineObject.applyForce(force) // Apply force
|
|
292
321
|
EngineObject.getMirrorSign() // Get mirror direction (1 or -1)
|
|
@@ -324,7 +353,7 @@ objectMaxSpeed = 1 // Clamp max speed to avoid fast objects missing c
|
|
|
324
353
|
gravity = (0,0) // How much gravity to apply to objects
|
|
325
354
|
|
|
326
355
|
// Engine Object functions
|
|
327
|
-
engineObjectsCollect(pos, size, objects=engineObjects)
|
|
356
|
+
engineObjectsCollect(pos, size, objects=engineObjects)
|
|
328
357
|
engineObjectsCallback(pos, size, callbackFunction, objects=engineObjects)
|
|
329
358
|
engineObjectsRaycast(start, end, objects=engineObjects)
|
|
330
359
|
engineObjectsDestroy()
|
|
@@ -341,6 +370,13 @@ engineObjectsDestroy()
|
|
|
341
370
|
|
|
342
371
|
```javascript
|
|
343
372
|
|
|
373
|
+
// Canvas Layer
|
|
374
|
+
CanvasLayer(position, size) // Create a canvas layer object
|
|
375
|
+
CanvasLayer.canvas // The canvas used by this layer
|
|
376
|
+
CanvasLayer.context // The 2D context of the canvas
|
|
377
|
+
CanvasLayer.getImageData() // Get image data from canvas
|
|
378
|
+
CanvasLayer.useWebGL() // Creates or updates WebGL texture
|
|
379
|
+
|
|
344
380
|
// LittleJS Layer System
|
|
345
381
|
TileLayer(position, size, tileInfo, scale) // Create a tile layer object
|
|
346
382
|
TileLayer.setData(layerPos, data, redraw) // Set data at position
|
|
@@ -353,7 +389,7 @@ TileLayer.drawCanvas2D(pos, size, angle, mirror, drawFunction) // Draw to 2
|
|
|
353
389
|
|
|
354
390
|
// Tile Layer Data Object
|
|
355
391
|
TileLayerData(tile, direction=0, mirror=false, color=WHITE) // Create tile data object
|
|
356
|
-
TileLayerData.clear()
|
|
392
|
+
TileLayerData.clear() // Clear this tile data
|
|
357
393
|
|
|
358
394
|
// Tile Collision Layer
|
|
359
395
|
TileCollisionLayer(position, size, tileInfo=tile()) // Create a tile collision layer object
|
|
@@ -387,8 +423,8 @@ particleEmitRateScale = 1 // Scales particles emit rate
|
|
|
387
423
|
|
|
388
424
|
```javascript
|
|
389
425
|
ASSERT(assert, output) // Asserts if the expression is false
|
|
390
|
-
debugRect(pos, size, color='#fff', time=0, angle=0, fill)
|
|
391
|
-
debugCircle(pos, radius, color='#fff', time=0, fill)
|
|
426
|
+
debugRect(pos, size, color='#fff', time=0, angle=0, fill) // Draw debug rectangle
|
|
427
|
+
debugCircle(pos, radius, color='#fff', time=0, fill) // Draw debug circle
|
|
392
428
|
debugPoint(pos, color, time, angle) // Draw debug point
|
|
393
429
|
debugLine(posA, posB, color, thickness=.1, time) // Draw debug line
|
|
394
430
|
debugText(text, pos, size=1, color='#fff', time=0, angle=0) // Draw debug text
|
package/src/engine.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
2
|
* LittleJS - The Tiny Fast JavaScript Game Engine
|
|
3
3
|
* MIT License - Copyright 2021 Frank Force
|
|
4
|
-
*
|
|
4
|
+
*
|
|
5
5
|
* Engine Features
|
|
6
6
|
* - Object oriented system with base class engine object
|
|
7
7
|
* - Base class object handles update, physics, collision, rendering, etc
|
|
@@ -30,7 +30,7 @@ const engineName = 'LittleJS';
|
|
|
30
30
|
* @type {string}
|
|
31
31
|
* @default
|
|
32
32
|
* @memberof Engine */
|
|
33
|
-
const engineVersion = '1.
|
|
33
|
+
const engineVersion = '1.14.2';
|
|
34
34
|
|
|
35
35
|
/** Frames per second to update
|
|
36
36
|
* @type {number}
|
|
@@ -120,7 +120,7 @@ function engineAddPlugin(updateFunction, renderFunction)
|
|
|
120
120
|
* // Basic engine startup
|
|
121
121
|
* engineInit(
|
|
122
122
|
* () => { console.log('Game initialized!'); }, // gameInit
|
|
123
|
-
* () => {
|
|
123
|
+
* () => { updateGameLogic(); }, // gameUpdate
|
|
124
124
|
* () => { updateUI(); }, // gameUpdatePost
|
|
125
125
|
* () => { drawBackground(); }, // gameRender
|
|
126
126
|
* () => { drawHUD(); }, // gameRenderPost
|
|
@@ -146,7 +146,7 @@ async function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, game
|
|
|
146
146
|
mainCanvasSize = vec2(mainCanvas.width, mainCanvas.height);
|
|
147
147
|
|
|
148
148
|
// disable smoothing for pixel art
|
|
149
|
-
overlayContext.imageSmoothingEnabled =
|
|
149
|
+
overlayContext.imageSmoothingEnabled =
|
|
150
150
|
mainContext.imageSmoothingEnabled = !tilesPixelated;
|
|
151
151
|
|
|
152
152
|
// setup gl rendering if enabled
|
|
@@ -194,7 +194,7 @@ async function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, game
|
|
|
194
194
|
deltaSmooth = frameTimeBufferMS;
|
|
195
195
|
frameTimeBufferMS = 0;
|
|
196
196
|
}
|
|
197
|
-
|
|
197
|
+
|
|
198
198
|
// update multiple frames if necessary in case of slow framerate
|
|
199
199
|
for (;frameTimeBufferMS >= 0; frameTimeBufferMS -= 1e3 / frameRate)
|
|
200
200
|
{
|
|
@@ -239,7 +239,7 @@ async function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, game
|
|
|
239
239
|
overlayContext.textBaseline = 'top';
|
|
240
240
|
overlayContext.font = '1em monospace';
|
|
241
241
|
overlayContext.fillStyle = '#000';
|
|
242
|
-
const text = engineName + ' ' + 'v' + engineVersion + ' / '
|
|
242
|
+
const text = engineName + ' ' + 'v' + engineVersion + ' / '
|
|
243
243
|
+ drawCount + ' / ' + engineObjects.length + ' / ' + averageFPS.toFixed(1)
|
|
244
244
|
+ (glEnable ? ' GL' : ' 2D') ;
|
|
245
245
|
overlayContext.fillText(text, mainCanvas.width-3, 3);
|
|
@@ -255,13 +255,13 @@ async function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, game
|
|
|
255
255
|
function updateCanvas()
|
|
256
256
|
{
|
|
257
257
|
if (headlessMode) return;
|
|
258
|
-
|
|
258
|
+
|
|
259
259
|
if (canvasFixedSize.x)
|
|
260
260
|
{
|
|
261
261
|
// clear canvas and set fixed size
|
|
262
262
|
mainCanvas.width = canvasFixedSize.x;
|
|
263
263
|
mainCanvas.height = canvasFixedSize.y;
|
|
264
|
-
|
|
264
|
+
|
|
265
265
|
// fit to window by adding space on top or bottom if necessary
|
|
266
266
|
const aspect = innerWidth / innerHeight;
|
|
267
267
|
const fixedAspect = mainCanvas.width / mainCanvas.height;
|
|
@@ -271,10 +271,10 @@ async function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, game
|
|
|
271
271
|
else
|
|
272
272
|
{
|
|
273
273
|
// clear canvas and set size to same as window
|
|
274
|
-
mainCanvas.width
|
|
274
|
+
mainCanvas.width = min(innerWidth, canvasMaxSize.x);
|
|
275
275
|
mainCanvas.height = min(innerHeight, canvasMaxSize.y);
|
|
276
276
|
}
|
|
277
|
-
|
|
277
|
+
|
|
278
278
|
// clear overlay canvas and set size
|
|
279
279
|
overlayCanvas.width = mainCanvas.width;
|
|
280
280
|
overlayCanvas.height = mainCanvas.height;
|
|
@@ -293,15 +293,14 @@ async function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, game
|
|
|
293
293
|
return startEngine();
|
|
294
294
|
|
|
295
295
|
// setup html
|
|
296
|
-
const styleRoot =
|
|
296
|
+
const styleRoot =
|
|
297
297
|
'margin:0;' + // fill the window
|
|
298
298
|
'overflow:hidden;' + // no scroll bars
|
|
299
299
|
'background:#000;' + // set background color
|
|
300
300
|
'user-select:none;' + // prevent hold to select
|
|
301
301
|
'-webkit-user-select:none;' + // compatibility for ios
|
|
302
|
-
(!touchInputEnable ? '' : // no touch css settings
|
|
303
302
|
'touch-action:none;' + // prevent mobile pinch to resize
|
|
304
|
-
'-webkit-touch-callout:none'
|
|
303
|
+
'-webkit-touch-callout:none';// compatibility for ios
|
|
305
304
|
rootElement.style.cssText = styleRoot;
|
|
306
305
|
drawCanvas = mainCanvas = document.createElement('canvas');
|
|
307
306
|
rootElement.appendChild(mainCanvas);
|
|
@@ -318,7 +317,7 @@ async function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, game
|
|
|
318
317
|
rootElement.appendChild(overlayCanvas);
|
|
319
318
|
overlayContext = overlayCanvas.getContext('2d');
|
|
320
319
|
|
|
321
|
-
// set
|
|
320
|
+
// set canvases
|
|
322
321
|
const styleCanvas = 'position:absolute;'+ // allow canvases to overlap
|
|
323
322
|
'top:50%;left:50%;transform:translate(-50%,-50%)'; // center on screen
|
|
324
323
|
mainCanvas.style.cssText = overlayCanvas.style.cssText = styleCanvas;
|
|
@@ -327,17 +326,18 @@ async function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, game
|
|
|
327
326
|
setCanvasPixelated(canvasPixelated);
|
|
328
327
|
setOverlayCanvasPixelated(overlayCanvasPixelated);
|
|
329
328
|
updateCanvas();
|
|
329
|
+
glPreRender();
|
|
330
330
|
|
|
331
331
|
// create offscreen canvas for image processing
|
|
332
332
|
workCanvas = new OffscreenCanvas(256, 256);
|
|
333
333
|
workContext = workCanvas.getContext('2d', { willReadFrequently: true });
|
|
334
|
-
|
|
334
|
+
|
|
335
335
|
// create promises for loading images
|
|
336
336
|
const promises = imageSources.map((src, textureIndex)=>
|
|
337
|
-
new Promise(resolve =>
|
|
337
|
+
new Promise(resolve =>
|
|
338
338
|
{
|
|
339
339
|
const image = new Image;
|
|
340
|
-
image.onerror = image.onload = ()=>
|
|
340
|
+
image.onerror = image.onload = ()=>
|
|
341
341
|
{
|
|
342
342
|
const textureInfo = new TextureInfo(image);
|
|
343
343
|
textureInfo.createWebGLTexture();
|
|
@@ -352,7 +352,7 @@ async function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, game
|
|
|
352
352
|
if (!imageSources.length)
|
|
353
353
|
{
|
|
354
354
|
// no images to load
|
|
355
|
-
promises.push(new Promise(resolve =>
|
|
355
|
+
promises.push(new Promise(resolve =>
|
|
356
356
|
{
|
|
357
357
|
const textureInfo = new TextureInfo(new Image);
|
|
358
358
|
textureInfos[0] = textureInfo;
|
|
@@ -364,7 +364,7 @@ async function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, game
|
|
|
364
364
|
if (showSplashScreen)
|
|
365
365
|
{
|
|
366
366
|
// draw splash screen
|
|
367
|
-
promises.push(new Promise(resolve =>
|
|
367
|
+
promises.push(new Promise(resolve =>
|
|
368
368
|
{
|
|
369
369
|
let t = 0;
|
|
370
370
|
console.log(`${engineName} Engine v${engineVersion}`);
|
|
@@ -596,7 +596,7 @@ function drawEngineSplashScreen(t)
|
|
|
596
596
|
line(36,20,60,20);
|
|
597
597
|
|
|
598
598
|
// engine front light
|
|
599
|
-
circle(60,30,4,PI,3*PI,color(3,2));
|
|
599
|
+
circle(60,30,4,PI,3*PI,color(3,2));
|
|
600
600
|
circle(60,30,4,PI,2*PI,color(3,3));
|
|
601
601
|
circle(60,30,4,PI,3*PI);
|
|
602
602
|
|
|
@@ -645,6 +645,6 @@ function drawEngineSplashScreen(t)
|
|
|
645
645
|
x[j?'strokeText':'fillText'](s[i],X+w/2,55.5,17*p);
|
|
646
646
|
X += w;
|
|
647
647
|
}
|
|
648
|
-
|
|
648
|
+
|
|
649
649
|
x.restore();
|
|
650
650
|
}
|