From ec04498d6603d3eeb5674c0fd7dc95fbf5592ef1 Mon Sep 17 00:00:00 2001 From: gocivici Date: Sun, 25 Feb 2024 15:43:20 +0300 Subject: [PATCH] -fix endless rendering issue in firefox --- public/classes/Sprite.js | 3 ++- public/index.js | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/public/classes/Sprite.js b/public/classes/Sprite.js index cb0f8d6..db84071 100644 --- a/public/classes/Sprite.js +++ b/public/classes/Sprite.js @@ -1,5 +1,5 @@ class Sprite{ - constructor({position, imageSrc,frames = 1,center,atPosition,sprites={up:'',down:'',left:'',right:''}}){ + constructor({position,skin, imageSrc,frames = 1,center,atPosition,sprites={up:'',down:'',left:'',right:''}}){ this.position = position this.atPosition = atPosition this.center = center @@ -16,6 +16,7 @@ class Sprite{ this.elapsedFrames = 0 this.frameBuffer = 7 this.sprites = sprites + this.skin = skin this.Up = new Image() this.Down = new Image() this.Left = new Image() diff --git a/public/index.js b/public/index.js index ac1bcb3..35cfca5 100644 --- a/public/index.js +++ b/public/index.js @@ -99,7 +99,9 @@ socket.on('updatePlayers', (bPlayers) =>{ fPlayers[id].clickY = bPlayer.clickY fPlayers[id].message = bPlayer.message fPlayers[id].username = bPlayer.username - spriteFunctionUpdate(fPlayers[id],bPlayer.skin) + if(fPlayers[id].skin!=bPlayer.skin){spriteFunctionUpdate(fPlayers[id],bPlayer.skin)} + // console.log(fPlayers[id].skin) + // console.log(bPlayer.skin) // fPlayers[id].sprites = spriteFunction(bPlayer.skin) // console.log(fPlayers[id]) @@ -225,6 +227,7 @@ document.querySelector('#textInput').addEventListener('submit',(event)=>{ fPlayers[socket.id].skin = "Green"; } socket.emit('skin',fPlayers[socket.id].skin); + spriteFunctionUpdate(fPlayers[socket.id],fPlayers[socket.id].skin); }else{ fPlayers[socket.id].message=document.querySelector('#input').value