|
| 1 | +<!-- |
| 2 | + If not stated otherwise in this file or this component's LICENSE file the |
| 3 | + following copyright and licenses apply: |
| 4 | +
|
| 5 | + Copyright 2020 Metrological |
| 6 | +
|
| 7 | + Licensed under the Apache License, Version 2.0 (the License); |
| 8 | + you may not use this file except in compliance with the License. |
| 9 | + You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | + Unless required by applicable law or agreed to in writing, software |
| 14 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + See the License for the specific language governing permissions and |
| 17 | + limitations under the License. |
| 18 | +--> |
| 19 | + |
| 20 | +<!DOCTYPE html> |
| 21 | +<html lang="en"> |
| 22 | +<head> |
| 23 | + <meta charset="UTF-8" /> |
| 24 | + <script src="../../../devtools/lightning-inspect.js"></script> |
| 25 | +</head> |
| 26 | +<body style="margin: 0; padding: 0"> |
| 27 | + <script type="module"> |
| 28 | + import lng from '../../../src/lightning.mjs'; |
| 29 | + //attachInspector(lng) |
| 30 | + |
| 31 | + let app = null; |
| 32 | + let canvas = null; |
| 33 | + const loadApp = () => { |
| 34 | + class BasicUsageExample extends lng.Application { |
| 35 | + static _template() { |
| 36 | + return { |
| 37 | + Bg: { |
| 38 | + src: "../landscape.jpg", scale: 1, |
| 39 | + }, |
| 40 | + Primary: { |
| 41 | + Main: {rect: true, renderToTexture: true, w: 900, h: 900, colorLeft: 0x000000FF, colorRight: 0xFF0000FF |
| 42 | + }, |
| 43 | + App: {alpha: 0.5, rect: true, w: 100, h: 100, scale: 1, texture: {type: lng.textures.NoiseTexture, x: 0, y: 0, w: 1000, h: 1000}} |
| 44 | + }, |
| 45 | + Overlay: {} |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + _handleLeft() { |
| 50 | + this.tag('Primary').setSmooth('x', this.tag('Primary').getSmooth('x') - 100) |
| 51 | + } |
| 52 | + |
| 53 | + _handleRight() { |
| 54 | + this.tag('Primary').setSmooth('x', this.tag('Primary').getSmooth('x') + 100) |
| 55 | + this._setState("Loading"); |
| 56 | + } |
| 57 | + |
| 58 | + _handleUp() { |
| 59 | + this.tag('Primary').setSmooth('y', this.tag('Primary').getSmooth('y') - 100) |
| 60 | + } |
| 61 | + |
| 62 | + _handleDown() { |
| 63 | + this.tag('Primary').setSmooth('y', this.tag('Primary').getSmooth('y') + 100) |
| 64 | + } |
| 65 | + |
| 66 | + } |
| 67 | + |
| 68 | + const options = { |
| 69 | + stage: { |
| 70 | + w: 900, h: 900, clearColor: 0xFF000000, canvas2d: false, useImageWorker: false, |
| 71 | + forceTxCanvasSource: true, |
| 72 | + pauseRafLoopOnIdle: true |
| 73 | + }, debug: true} |
| 74 | + |
| 75 | + app = new BasicUsageExample(options); |
| 76 | + canvas = app.stage.getCanvas() |
| 77 | + document.body.appendChild(app.stage.getCanvas()); |
| 78 | + } |
| 79 | + |
| 80 | + |
| 81 | + document.addEventListener("keydown", (e) => { |
| 82 | + // spacebar |
| 83 | + if (e.keyCode === 32) { |
| 84 | + if (app) { |
| 85 | + app.destroy(); |
| 86 | + document.body.removeChild(canvas); |
| 87 | + canvas = null; |
| 88 | + return app = null; |
| 89 | + } |
| 90 | + |
| 91 | + loadApp(); |
| 92 | + } |
| 93 | + }) |
| 94 | + </script> |
| 95 | +</body> |
| 96 | +</html> |
0 commit comments