Jump to content

Multiplayer Game Rendering Existing Characters in Multiple Rooms


zazou
 Share

Recommended Posts

Hey guys,
I'm building a multiplayer art game which involves multiple rooms. I'm using Phaser for the pixel manipulation stuff, and express/node with sockets for the back end/front end communication.

Currently:

The server has a players object which keeps track of all the connected players and their positions/rooms.

The client has an object for each Level, which contains all the information about remote players.

At present they are currently doing their job correctly, as the server and clients seem to know about where the players are at any moment in time. 

The Problem: When a player enters a new map, I cannot figure out how to render all the remote Players that are already present in that room.  Note that it works fine when you are inside a room, and somebody enters your room : You can see them, and they can't see you.

This is the information about remote players that is available to the client when they enter the viewing room (in an object called viewingPlayers).

 

post-8567-0-15054100-1429213656.png


This is what the 'remoteplayer' class looks like. This class is essentially an animated facade of another player.
 

var RemotePlayer = function (id, game, player, startX, startY) {    var x = startX;    var y = startY;    this.game = game;    this.alive = true;    this.player = game.add.sprite(x, y, 'dude');    this.id = id;    //animations here    this.lastPosition = { x: x, y: y };};

this remote player has an update function, that is called in the update cycle of the client.

RemotePlayer.prototype.update = function() {    //animations go here    this.lastPosition.x = this.player.x;    this.lastPosition.y = this.player.y;};

What exactly is necessary for an object containing several 'remote player' sprites to be rendered to the screen?  As long as remotePlayer.alive is true, the remote players 'last position' is updated like this:
 

  for (var id in viewingPlayers)        {            if (viewingPlayers[id].alive)                viewingPlayers[id].update();        }

Does anyone have any ideas about what I am missing?

Here is the github code: (https://github.com/sdlovecraft/virtual-gallery). I believe the problem is  isolated in the /public/js/viewing1.js file: where  the remotePlayers Obj  (viewingPlayers)  is failing to be rendered.

Any help on this would be greatly, greatly appreciated.

 

Link to comment
Share on other sites

Maybe I'm not understanding this correctly, but what stops you from just sending a message to a player when he joins a room that informs him of which other players are in the room and their positions? Then you can just create sprites using this information. I'm doing something similar in my own multiplayer game. When a player joins a hosted game, he needs to be informed of which other players are in the game:

 

https://github.com/ahung89/bomb-arena/blob/master/server/lobby.js#L61

Link to comment
Share on other sites

Thanks so much for getting back to me! It turns out I was trying to render the players before I had initialized the map properly, which is why they were not appearing on my page. Doh! Your code has been helpful. Thanks :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...