|
1 |
| -var config = { |
2 |
| - width: 800, |
3 |
| - height: 600, |
4 |
| - type: Phaser.CANVAS, |
5 |
| - parent: 'phaser-example', |
6 |
| - scene: { |
7 |
| - create: create, |
8 |
| - update: update |
9 |
| - } |
10 |
| -}; |
| 1 | +let i |
| 2 | +let stars = []; |
| 3 | +let cameraRotation = 0; |
| 4 | +let camera0, camera1, camera2, camera3; |
11 | 5 |
|
12 |
| -var game = new Phaser.Game(config); |
| 6 | +class Example extends Phaser.Scene |
| 7 | +{ |
| 8 | + create () |
| 9 | + { |
| 10 | + let radius = 20; |
| 11 | + let radius2 = radius * 2; |
| 12 | + let maxWidth = (400 / radius2)|0; |
13 | 13 |
|
14 |
| -var t = 0; |
15 |
| -var graphics1; |
16 |
| -var graphics2; |
| 14 | + for (let i = 0; i < 80; ++i) |
| 15 | + { |
| 16 | + let graphics = this.add.graphics({x: radius + (i % maxWidth) * radius2, y: radius + ((i / maxWidth)|0) * radius2}); |
| 17 | + this.drawStar(graphics, 0, 0, 5, radius, radius / 2, 0xff0000, 0xFFFF00); |
| 18 | + graphics.fillStyle(0xFFFF00 + (i % 0xFF), 1.0); |
| 19 | + stars.push(graphics); |
| 20 | + stars[i].rotation += 0.1; |
| 21 | + } |
17 | 22 |
|
18 |
| -function create () |
19 |
| -{ |
20 |
| - graphics2 = this.add.graphics({x: -16, y: 0}).lineStyle(28, 0x00ffff, 0.8); |
21 |
| - graphics1 = this.add.graphics().lineStyle(28, 0x0000ff, 0.8); |
| 23 | + this.cameras.main.setSize(400, 300); |
22 | 24 |
|
23 |
| - // Create the circles |
| 25 | + camera0 = this.cameras.main; |
| 26 | + camera1 = this.cameras.add(400, 0, 400, 300); |
| 27 | + camera2 = this.cameras.add(0, 300, 400, 300); |
| 28 | + camera3 = this.cameras.add(400, 300, 400, 300); |
| 29 | + } |
24 | 30 |
|
25 |
| - var radius1 = 64; |
26 |
| - var radius2 = 32; |
| 31 | + update () |
| 32 | + { |
| 33 | + camera0.scrollX = Math.cos(cameraRotation) * 100; |
| 34 | + camera0.scrollY = Math.sin(cameraRotation) * 100; |
| 35 | + camera1.shake(100, 0.01); |
| 36 | + camera2.flash(2000); |
| 37 | + camera3.fade(2000); |
| 38 | + camera3.rotation = Math.sin(cameraRotation); |
| 39 | + camera3.zoom = 0.5 + Math.abs(Math.sin(cameraRotation)); |
| 40 | + if (camera3._fadeAlpha >= 1.0) |
| 41 | + { |
| 42 | + camera3._fadeAlpha = 0.0; |
| 43 | + camera3.fade(1000); |
| 44 | + } |
| 45 | + for (let i = 0; i < stars.length; ++i) |
| 46 | + { |
| 47 | + let star = stars[i]; |
| 48 | + star.rotation += 0.01; |
| 49 | + star.scaleX = 0.5 + Math.abs(Math.sin(star.rotation)); |
| 50 | + star.scaleY = 0.5 + Math.abs(Math.sin(star.rotation)); |
| 51 | + } |
| 52 | + cameraRotation += 0.01; |
| 53 | + } |
27 | 54 |
|
28 |
| - for (var i = 0; i < 8; i++) |
| 55 | + drawStar (graphics, cx, cy, spikes, outerRadius, innerRadius, color, lineColor) |
29 | 56 | {
|
30 |
| - graphics1.strokeCircle(400, 300, radius1); |
31 |
| - graphics2.strokeCircle(400, 300, radius2); |
| 57 | + let rot = Math.PI / 2 * 3; |
| 58 | + let x = cx; |
| 59 | + let y = cy; |
| 60 | + let step = Math.PI / spikes; |
| 61 | + graphics.lineStyle(1, lineColor, 1.0); |
| 62 | + graphics.fillStyle(color, 1.0); |
| 63 | + graphics.beginPath(); |
| 64 | + graphics.moveTo(cx, cy - outerRadius); |
| 65 | + for (i = 0; i < spikes; i++) { |
| 66 | + x = cx + Math.cos(rot) * outerRadius; |
| 67 | + y = cy + Math.sin(rot) * outerRadius; |
| 68 | + graphics.lineTo(x, y); |
| 69 | + rot += step; |
32 | 70 |
|
33 |
| - radius1 += 64; |
34 |
| - radius2 += 64; |
| 71 | + x = cx + Math.cos(rot) * innerRadius; |
| 72 | + y = cy + Math.sin(rot) * innerRadius; |
| 73 | + graphics.lineTo(x, y); |
| 74 | + rot += step; |
| 75 | + } |
| 76 | + graphics.lineTo(cx, cy - outerRadius); |
| 77 | + graphics.closePath(); |
| 78 | + graphics.fillPath(); |
| 79 | + graphics.strokePath(); |
35 | 80 | }
|
36 |
| - |
37 | 81 | }
|
38 | 82 |
|
39 |
| -function update () |
40 |
| -{ |
41 |
| - t += 0.1; |
42 |
| - |
43 |
| - graphics1.x += Math.sin(t) * 2; |
44 |
| - graphics1.y += Math.cos(t) * 2; |
45 | 83 |
|
46 |
| - graphics2.x += Math.sin(t) * 3; |
47 |
| - graphics2.y += Math.cos(t) * 3; |
| 84 | +const config = { |
| 85 | + type: Phaser.WEBGL, |
| 86 | + parent: 'phaser-example', |
| 87 | + width: 800, |
| 88 | + height: 600, |
| 89 | + scene: [ Example ] |
| 90 | +}; |
48 | 91 |
|
49 |
| -} |
| 92 | +const game = new Phaser.Game(config); |
0 commit comments