timer fix
This commit is contained in:
parent
75be68ebb6
commit
9aed8171d0
10
backend.js
10
backend.js
@ -31,7 +31,8 @@ io.on('connection', (socket)=>{
|
|||||||
clickX:615,
|
clickX:615,
|
||||||
clickY:136,
|
clickY:136,
|
||||||
message:'',
|
message:'',
|
||||||
username:"Visitor"
|
username:"Visitor",
|
||||||
|
timeoutId:0
|
||||||
} //create player object with new socket id property
|
} //create player object with new socket id property
|
||||||
|
|
||||||
io.emit('updatePlayers',bPlayers)
|
io.emit('updatePlayers',bPlayers)
|
||||||
@ -56,15 +57,16 @@ io.on('connection', (socket)=>{
|
|||||||
})
|
})
|
||||||
|
|
||||||
socket.on('message',(message)=>{
|
socket.on('message',(message)=>{
|
||||||
|
let timeoutId;
|
||||||
clearTimeout(timeoutHandle);
|
clearTimeout(bPlayers[socket.id].timeoutId);
|
||||||
bPlayers[socket.id].message = message
|
bPlayers[socket.id].message = message
|
||||||
|
|
||||||
function startTimer() {
|
function startTimer() {
|
||||||
timeoutHandle = setTimeout(() => {
|
timeoutId = setTimeout(() => {
|
||||||
bPlayers[socket.id].message = ''
|
bPlayers[socket.id].message = ''
|
||||||
}, 4000);
|
}, 4000);
|
||||||
}
|
}
|
||||||
|
bPlayers[socket.id].timeoutId = timeoutId
|
||||||
startTimer();
|
startTimer();
|
||||||
|
|
||||||
console.log(bPlayers)
|
console.log(bPlayers)
|
||||||
|
@ -16,7 +16,7 @@ let row = 0;
|
|||||||
let readyNow = false
|
let readyNow = false
|
||||||
let animationFrame = 0;
|
let animationFrame = 0;
|
||||||
let pageVisible = true;
|
let pageVisible = true;
|
||||||
|
let timeoutHandle;
|
||||||
|
|
||||||
// let atPosition = true;
|
// let atPosition = true;
|
||||||
// img.src = 'demaSprite.png';
|
// img.src = 'demaSprite.png';
|
||||||
@ -86,6 +86,7 @@ socket.on('updatePlayers', (bPlayers) =>{
|
|||||||
fPlayers[id].clickY = bPlayer.clickY
|
fPlayers[id].clickY = bPlayer.clickY
|
||||||
fPlayers[id].message = bPlayer.message
|
fPlayers[id].message = bPlayer.message
|
||||||
fPlayers[id].username = bPlayer.username
|
fPlayers[id].username = bPlayer.username
|
||||||
|
|
||||||
//update player position without animation if tab is inactive
|
//update player position without animation if tab is inactive
|
||||||
if (document.hidden) {
|
if (document.hidden) {
|
||||||
fPlayers[id].position.x = bPlayer.x
|
fPlayers[id].position.x = bPlayer.x
|
||||||
|
Loading…
Reference in New Issue
Block a user