From 6e79154cad182010dda01d5302bb0306f413c1b0 Mon Sep 17 00:00:00 2001 From: LoveEevee Date: Sat, 24 Nov 2018 17:09:08 +0300 Subject: [PATCH] SongBg: Reduce background resolution on mobile --- public/src/css/songbg.css | 3 ++- public/src/js/game.js | 3 +++ public/src/js/loadsong.js | 24 ++++++++++++++++++++++-- public/src/js/view.js | 4 ++-- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/public/src/css/songbg.css b/public/src/css/songbg.css index 7819f97..a9f1392 100644 --- a/public/src/css/songbg.css +++ b/public/src/css/songbg.css @@ -22,7 +22,8 @@ } #song-stage{ height: calc(44 / 720 * 100vh); - background-position: center; + background-position: center bottom; + background-repeat-y: no-repeat; } .portrait #songbg{ height: 63.4%; diff --git a/public/src/js/game.js b/public/src/js/game.js index 8b3ae85..3072cf4 100644 --- a/public/src/js/game.js +++ b/public/src/js/game.js @@ -350,6 +350,8 @@ class Game{ this.mainMusicPlaying = false this.view.pauseMove(0, true) this.view.gameDiv.classList.add("game-paused") + this.view.lastMousemove = this.view.getMS() + this.view.cursorHidden = false }else{ assets.sounds["cancel"].play() this.paused = false @@ -357,6 +359,7 @@ class Game{ this.startDate += currentDate - this.latestDate this.sndTime = currentDate - snd.buffer.getTime() * 1000 this.view.gameDiv.classList.remove("game-paused") + this.view.pointer() } } isPaused(){ diff --git a/public/src/js/loadsong.js b/public/src/js/loadsong.js index 7ae5515..ff8d175 100644 --- a/public/src/js/loadsong.js +++ b/public/src/js/loadsong.js @@ -63,11 +63,31 @@ class loadSong{ let filenameAb = filename + (i === 0 ? "a" : "b") let img = document.createElement("img") promises.push(pageEvents.load(img).then(() => { - assets.image[filenameAb] = img + if(this.touchEnabled){ + return new Promise((resolve, reject) => { + var canvas = document.createElement("canvas") + var w = Math.floor(img.width / 2) + var h = Math.floor(img.height / 2) + canvas.width = w + canvas.height = h + var ctx = canvas.getContext("2d") + ctx.drawImage(img, 0, 0, w, h) + canvas.toBlob(blob => { + let img2 = document.createElement("img") + pageEvents.load(img2).then(() => { + assets.image[filenameAb] = img2 + resolve() + }, reject) + img2.src = URL.createObjectURL(blob) + }) + }) + }else{ + assets.image[filenameAb] = img + } })) img.src = gameConfig.assets_baseurl + "img/" + filenameAb + ".png" } - return Promise.all(promises).then(resolve, reject) + Promise.all(promises).then(resolve, reject) } }) } diff --git a/public/src/js/view.js b/public/src/js/view.js index ad4b69f..a36e1b4 100644 --- a/public/src/js/view.js +++ b/public/src/js/view.js @@ -1523,7 +1523,7 @@ } } onmousemove(event){ - this.lastMousemove = this.controller.getElapsedTime() + this.lastMousemove = this.getMS() this.cursorHidden = false if(!this.multiplayer && this.controller.game.paused){ @@ -1568,7 +1568,7 @@ mouseIdle(){ var lastMouse = pageEvents.getMouse() if(lastMouse && !this.cursorHidden){ - if(this.controller.getElapsedTime() >= this.lastMousemove + 2000){ + if(this.getMS() >= this.lastMousemove + 2000){ this.cursor.style.top = lastMouse.clientY + "px" this.cursor.style.left = lastMouse.clientX + "px" this.cursor.style.pointerEvents = "auto"