quyueting 5 年之前
父節點
當前提交
908c7c82e9
共有 2 個文件被更改,包括 10 次插入2 次删除
  1. 10 2
      minigame/WebContent/js/main.js
  2. 0 0
      minigame/WebContent/sound/shake.mp3

+ 10 - 2
minigame/WebContent/js/main.js

@@ -17,6 +17,7 @@ createjs.Sound.registerSound("sound/background_music.mp3", "bgm");
 createjs.Sound.registerSound("sound/cut.mp3", "cut");//切菜
 createjs.Sound.registerSound("sound/oil.mp3", "oil");//空锅倒油(肉、油麦菜)
 createjs.Sound.registerSound("sound/soup.mp3", "soup");//煮
+createjs.Sound.registerSound("sound/shake.mp3", "shake");//摇
 
 window.user_info = {
     uid: 0,
@@ -626,7 +627,7 @@ function handleComplete(evt, comp) {
         } else {
             alert('您的手机不支持摇一摇功能!');
         }
-
+        
         //获取加速度信息
         //通过监听上一步获取到的x, y, z 值在一定时间范围内的变化率,进行设备是否有进行晃动的判断。
         //而为了防止正常移动的误判,需要给该变化率设置一个合适的临界值。
@@ -635,7 +636,7 @@ function handleComplete(evt, comp) {
         var x, y, z, last_x = 0,
             last_y = 0,
             last_z = 0;
-
+		var createTime = false;
         function deviceMotionHandler(eventData) {
             var acceleration = eventData.accelerationIncludingGravity;
             var curTime = new Date().getTime();
@@ -647,6 +648,13 @@ function handleComplete(evt, comp) {
                 z = acceleration.z;
                 var speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000;
                 if (speed > SHAKE_THRESHOLD) {
+					
+					if(!createTime) {
+						createTime = true;
+						var video = createjs.Sound.play("shake");//播放
+						setTimeout(function(){ video.paused = true; }, 5000);
+					}
+					
                     $(".shake-mode2").hide();
                     $(".shake-mode").show();
                     shake_cnt++;

minigame/WebContent/sound/摇手机.mp3 → minigame/WebContent/sound/shake.mp3