Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7999705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:34:48+00:00 2026-06-04T15:34:48+00:00

I am using node.js and express, and I am calling server-side functions and syncing

  • 0

I am using node.js and express, and I am calling server-side functions and syncing variables using nowjs. Suppose the user is drawn as a sprite on the canvas. His x,y coordinates are kept server-side in a “position” array.

Server-side:

position = { x : 0; y : 0 } 

updatePosition = function (a,b) 
{ 
  playerPosition.x += a; 
  playerPosition.y += b; 
} 

Client-side:

if keypress('right'){ updatePosition(32,0); }

These are pseudocode. When the user presses the ‘right’ button, the server-side “updatePosition” function is called, which adds 32 (pixels) to the x-coordinate of the “position” array. This array is then shared with the client, and the new position is drawn on the canvas using client-side function.

Suppose I don’t want to draw the sprite at the new position instantly. I want to play a walking animation that gradually moves the sprite 32 pixels to the right, and takes say 1 second to complete. I might implement it this way:

  1. User presses the ‘right’ button.
  2. The animation starts playing client-side.
  3. updatePosition is called server-side as usual.
  4. When animation on the client finishes, check if the final position client-side matches the coordinates stored server side.

When the user presses the ‘right’ button/key, he cannot repeat the keypress until 1 second later. The 1 second long “walking” animation has to complete and final position checked with the server-side coordinates before he can press ‘right’ again to move his sprite.

Question: How do I keep track of the 1 second server side? I can’t do it client-side because the user will be able to hack his client to reduce the animation time.

Is the solution to “timestamp” the position array? E.g. position = { x : 0; y : 0, time: 0 }. If the user presses the ‘right’ button again, the server would check to see if the last position update was greater than 1 second ago. If less than 1 second, the server ignores it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:34:49+00:00Added an answer on June 4, 2026 at 3:34 pm

    Why not simply storing a “lock” in the user session?

    session.editLock = new Date().getTime();
    

    When another edit is triggered by the client, just:

    if(session.editLock && new Date().getTime() - session.editLock > 1000) {
      // Return error
    }
    

    Modifying the position object doesn’t feel right to me. A position object is meant to store position, not time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating node.js app using express, everyauth and now.js. I have a server-side
I am building a website/app using node.js, express and nowjs. Once user log into
I'm using Express and Node.jx 0.6.7. Server is EC2 Small instance.. For some reason,
I am using express with node.js for a http server. I store the response
I am using node and express. To register a controller I call: app.get('/user/:id', function
I have the following express node.js app. It's using the 'redis' npm package. app.get(/test,function(req,res){
I am currently using the following versions of node & express (ubuntu): node: 0.6.12
I'm interested in using Node.js as a socket server for stream-based communication with tens
I'm using Node.js with Express, Connect, and Jade. I want to provide an absolute
I'm using node.js and express to handle HTTP requests and responses. By using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.