Hey all, me and some other buds are creating a game where we need to have multiple players in ‘real time’. I have tested the solution of using a database/text file to handle the player positions, but it used huge amounts of CPU w/ only 2 players. So I wrote a socket server in PHP, and now I need help creating the AS part of it
I already wrote a bunch of accessors, I would like you to tell me if this is the best way to do it, as I am a total AS n00b.
/* Handle the receiving of player positions */
XMLSocket.prototype.onData = function (PlayerList)
{
var i = 0;
var CurrentUsername = "";
var PlayerArray = PlayerList.split("|");
for(Container in PlayerArray)
{
if (i == 0)
{
CurrentUsername = Container;
i = i + 1;
}
if (i == 1)
{
//assign coordinates to player with CurrentUsername;
i = 0;
CurrentUsername = "";
}
}
}
/* Initialize socket connection */
_global.InitSocket = function(Username)
{
var IP = "xxx.xxx.xxx.xxx"; // IP address of socket server
var Port = "xxxx"; // Port of socket server to listen on
_global.socket = new XMLSocket(); // Create socket object
_global.socket.connect(IP, Port); // Connect to socket
_global.socket.send(Username); // Send username
_global.socket.send("0,0"); // Initial position
}
/* Close socket connection */
_global.CloseSocket = function()
{
_global.socket.close();
}
/* Send new player position to socket */
_global.SendPosition = function(Position)
{
_global.socket.send(Position);
}
InitSocket("PLAYERUSERNAME");