timer fix

This commit is contained in:
gocivici 2023-09-26 18:40:27 +03:00
parent 75be68ebb6
commit 9aed8171d0
2 changed files with 8 additions and 5 deletions

View File

@ -31,7 +31,8 @@ io.on('connection', (socket)=>{
clickX:615,
clickY:136,
message:'',
username:"Visitor"
username:"Visitor",
timeoutId:0
} //create player object with new socket id property
io.emit('updatePlayers',bPlayers)
@ -56,15 +57,16 @@ io.on('connection', (socket)=>{
})
socket.on('message',(message)=>{
clearTimeout(timeoutHandle);
let timeoutId;
clearTimeout(bPlayers[socket.id].timeoutId);
bPlayers[socket.id].message = message
function startTimer() {
timeoutHandle = setTimeout(() => {
timeoutId = setTimeout(() => {
bPlayers[socket.id].message = ''
}, 4000);
}
bPlayers[socket.id].timeoutId = timeoutId
startTimer();
console.log(bPlayers)

View File

@ -16,7 +16,7 @@ let row = 0;
let readyNow = false
let animationFrame = 0;
let pageVisible = true;
let timeoutHandle;
// let atPosition = true;
// img.src = 'demaSprite.png';
@ -86,6 +86,7 @@ socket.on('updatePlayers', (bPlayers) =>{
fPlayers[id].clickY = bPlayer.clickY
fPlayers[id].message = bPlayer.message
fPlayers[id].username = bPlayer.username
//update player position without animation if tab is inactive
if (document.hidden) {
fPlayers[id].position.x = bPlayer.x