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 7574615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:28:42+00:00 2026-05-30T16:28:42+00:00

this is my client: http://pastebin.com/C9PHzTQg this is my server: http://pastebin.com/j2dfL84d Now is multiplayer rect’s,

  • 0

this is my client: http://pastebin.com/C9PHzTQg
this is my server: http://pastebin.com/j2dfL84d

Now is “multiplayer” rect’s, but how to do movement?

I am send to ‘b’ – “UP”, “LEFT”, “RIGHT”, “DOWN” and how to handle ant move player?

Sorry for my bad english language.

  • 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-05-30T16:28:43+00:00Added an answer on May 30, 2026 at 4:28 pm

    First, you need to learn prototypical inheritance! As it is, each Player will have it’s own copy of the draw method, so put draw on Player.prototype instead:

    var Player = function(context, x, y) {
        this.context = context;
        this.x = x;
        this.y = y;
    };
    
    Player.prototype = {
        draw: function() {
            this.context.fillRect(this.x, this.y, 16, 16);
        }
    };
    

    Then, I suggest you add a move method to Player:

    Player.prototype = {
        draw: function() {
            this.context.fillRect(this.x, this.y, 16, 16);
        },
    
        move: function(direction) {
            // direction is "UP", "DOWN", "LEFT" or "RIGHT"
            switch(direction) {
                case "UP":
                    this.y += 16;
                    break;
                // ...
            }
        }
    };
    

    Then, in your message handler, you just have to:

    socket.on('b', function(data) {
        players[data.player].move(data.direction);
        draw();
    });
    

    In the server, you would emit('b', { player: playerId, direction: "UP" }, for example.

    Update: Instead of draw inside socket.on('b', ... above, you could have something like:

    setInterval(draw, 100);
    

    To redraw every 100 ms. It depends on the type of game, I guess.

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

Sidebar

Related Questions

I've just seen this library https://github.com/technomancy/clojure-http-client with this snippet of code on the README
I am trying to send a simple HTTP request like this: var client =
I have the following code: http://pastebin.com/U9qYSmET When I try to telnet into my server
I'm currently working in the following site for a client http://minta.jvsoftware.com/ but I'm trying
i'have a js client with JQuery, this js call a page (GET HTTP) and
A web service return to my flex3 client this custom exception: <SOAP-ENV:Fault xmlns:ro=urn:Gov2gLibrary xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/
I'm following this guide: http://code.google.com/intl/it-IT/apis/documents/docs/2.0/developers_guide_java.html I just need to retrieve a token and use
I get the error com.google.gdata.util.AuthenticationException: Unknown authorization header at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:600) ~[gdata-core-1.0.jar:na] at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563) ~[gdata-core-1.0.jar:na]
I am building an HTTP client based on the example on HTTP server given
I'm having trouble using Zend HTTP on a URL: $client = new Zend_Http_Client('http://xxfire_killumiex.api.channel.livestream.com/2.0/info.json'); $feed

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.