张延森 3 gadus atpakaļ
vecāks
revīzija
1f6d2fc280

+ 5
- 0
public/index.html Parādīt failu

@@ -10,6 +10,11 @@
10 10
     为岸线圆梦,摩天轮圆满大作战!
11 11
   </title>
12 12
   <script src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
13
+  <!-- <script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
14
+  <script>
15
+    // VConsole 默认会挂载到 `window.VConsole` 上
16
+    var vConsole = new window.VConsole();
17
+  </script> -->
13 18
 </head>
14 19
 
15 20
 <body>

+ 20
- 3
src/pages/game/algorithm/index.js Parādīt failu

@@ -8,11 +8,14 @@ import { drawPedestal } from './pedestal';
8 8
 import drawBullets from './bullet';
9 9
 import { drawCounter } from './counter';
10 10
 
11
-export default ({ el, center, rotateSpeed = 0.015, speed = -5 }) => {
11
+export default ({ el, center, rotateSpeed = 0.045, speed = -12 }) => {
12 12
     
13 13
   // 修复一个单页面应用, 不能重复加载图片的bug
14 14
   Two.Texture.ImageRegistry = new Two.Registry();
15 15
 
16
+  // 30FPS
17
+  const FRAMERATE = 1000 / 30;
18
+
16 19
   // 初始化
17 20
   const two = new Two({
18 21
     type: Two.Types.svg,
@@ -49,6 +52,8 @@ export default ({ el, center, rotateSpeed = 0.015, speed = -5 }) => {
49 52
 
50 53
   // 整体绘制结束  
51 54
   two.update();
55
+  // 页面刷新定时器
56
+  let frameRateInterval = null;
52 57
 
53 58
   // 下面是业务逻辑部分
54 59
 
@@ -109,16 +114,28 @@ export default ({ el, center, rotateSpeed = 0.015, speed = -5 }) => {
109 114
       status = 1; // 游戏开始
110 115
       clip.bulletLoad() // 先上膛一颗子弹
111 116
       wheel.rotate();
112
-      two.play();
117
+      // two.play();
118
+
119
+      console.log('----------FRAME RATE---------', FRAMERATE)
120
+
121
+      if (frameRateInterval) {
122
+        clearInterval(frameRateInterval)
123
+      } else {
124
+        setInterval(function() {
125
+          two.update();
126
+        }, FRAMERATE);
127
+      }
113 128
     },
114 129
     pause: () => {
115 130
       wheel.stop();
116
-      two.pause();
131
+      // two.pause();
132
+      clearInterval(frameRateInterval)
117 133
     },
118 134
     destroy: () => {
119 135
       two.unbind('update');
120 136
       two.pause();
121 137
       el.removeChild(two.renderer.domElement);
138
+      clearInterval(frameRateInterval);
122 139
     }
123 140
   }
124 141
 }

+ 1
- 1
src/pages/game/algorithm/pedestal.js Parādīt failu

@@ -34,7 +34,7 @@ export function drawPedestal ({ two, center }) {
34 34
   pedestalBox.scale = scale;
35 35
 
36 36
   // 绘制底座上的绳子
37
-  const ropeSequence = two.makeImageSequence(ropeImageList, x, y, 40); // 40 是不断调式出来的频率, 需要跟 speed 匹配
37
+  const ropeSequence = two.makeImageSequence(ropeImageList, x, y, 30); // 40 是不断调式出来的频率, 需要跟 speed 匹配
38 38
   ropeSequence.scale = new Two.Vector(scale, scale);
39 39
 
40 40
   return {

+ 9
- 1
src/pages/game/algorithm/wheel.js Parādīt failu

@@ -16,8 +16,10 @@ export function drawWheel({ two, center, rotateSpeed, cages }) {
16 16
   const perAngle = Math.PI / cages.length;
17 17
   
18 18
   // 摩天轮与轿厢旋转
19
+  let _count = 0;
19 20
   let rotateAngle = 0;
20 21
   const wheelRotate = () => {
22
+    _count += 1;
21 23
     rotateAngle += rotateSpeed
22 24
     wheelArc.rotation = rotateAngle
23 25
     cages.forEach(cage => {
@@ -34,7 +36,13 @@ export function drawWheel({ two, center, rotateSpeed, cages }) {
34 36
 
35 37
   return {
36 38
     raduis,
37
-    rotate: () => two.addEventListener('update', wheelRotate),
39
+    rotate: () => {
40
+      console.log('----------START---------')
41
+      two.addEventListener('update', wheelRotate)
42
+      const t = setTimeout(() => {
43
+        console.log('----------1 MINUTES---------', _count)
44
+      }, 1000)
45
+    },
38 46
     stop: () => two.removeEventListener('update', wheelRotate),
39 47
   }
40 48
 }