Jump to content

Phaser sockets multiplayer


The_dude8080
 Share

Recommended Posts

1 hour ago, carlosnufe said:

Normal case is when server broadcasts and the clients are subscribed and ready for listening whatever event thrown. Then, on client side that events are handled

so I would use the already implemented phaser update function after clients are in game?

Link to comment
Share on other sites

11 hours ago, carlosnufe said:

Hi again ;), 

No, you should not, if you look at their doc you'll find how to subscribe to server events. For instance, 


var socket = io('http://hostname');
socket.on('nameEvent', function (data) {
  console.log(data);
});

Try to understand how it works, it's Javascript itself.

Hmm so bassicaly the phaser update function is made for single player games where there is no player interactivity

Yeah I have done some things like that with sockets. Never a multiplayer game

Link to comment
Share on other sites

In update() method usually is developed stuff about physics, collisions, player movement and so on. You update information regarding fps. 

Socket callback has a close behaviour but with the difference that you will throw your own "update function" which it should not the phaser update. You can use a function to handle player positions, for example, passing n parameters and do some stuff. This function could be used in update phaser function and socket callback.

As I said, it's Javascript itself.

Hope help you.

Link to comment
Share on other sites

9 hours ago, carlosnufe said:

In update() method usually is developed stuff about physics, collisions, player movement and so on. You update information regarding fps. 

Socket callback has a close behaviour but with the difference that you will throw your own "update function" which it should not the phaser update. You can use a function to handle player positions, for example, passing n parameters and do some stuff. This function could be used in update phaser function and socket callback.

As I said, it's Javascript itself.

Hope help you.

Thanks that helps a lot already. Just to make sure ... everything that doesn't go in sockets is not shown in multiplayer right? For example if I handled every player movement on the server side by checking if he is pressing some key and increasing its Location it would be seen by every player. However if the player had the ability to shoot bullets but I didn't handle that event on the server side / sockets by sending and x / y position of the player bullet only the player who shot the bullet could see it? To sum up, everything that must be seen by every player must be handled by sockets events / server?

Link to comment
Share on other sites

Everything you want all clients to see should be handled by the server. Broadcast them to the proper room. But if you want to do a lot of the calculations on the server your going to want to implement phaser on your server or something that will react similar to phaser on the server. (this might be a lot of work, generally I just allow one client to control its own, like its character and it updates all clients, just make sure everything is consistent in every client)

Link to comment
Share on other sites

10 hours ago, rgk said:

Everything you want all clients to see should be handled by the server. Broadcast them to the proper room. But if you want to do a lot of the calculations on the server your going to want to implement phaser on your server or something that will react similar to phaser on the server. (this might be a lot of work, generally I just allow one client to control its own, like its character and it updates all clients, just make sure everything is consistent in every client)

Well I think this is enough for a start :) Thank you all. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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