我需要在i < one.length
内进行websocket.send()
,但似乎无效。或者还有其他事情在发生吗?
我尝试了一些websocket.onmessage()
,但在console.log()
时没有执行此操作。它确实正确执行type=='request_for_existing_players'
。
我不知道如何从console.log("player number on connect is " + msg.player_number);
文件登录。
我正在使用XAMPP Apache端口80。
的index.php:
server.php
server.php:
websocket.onmessage = function(ev) {
var msg = JSON.parse(ev.data); //PHP sends Json data
var type = msg.type; //message type
if(type == 'new_player')
{
var image = new Image();
image.src = 'player.jpg';
array_of_player_images.push(image);
if(is_self)
{
console.log("player number on connect is " + msg.player_number);
is_self = false;
this_player = new Player(msg.starting_coordinate_x, msg.starting_coordinate_y,
player_width, player_height, player_speed,msg.player_number);
array_of_players.push(this_player);
window.click = new point(this_player.point.x, this_player.point.y);
var message = {
type: "request_for_existing_players"
};
websocket.send(JSON.stringify(message));
}
else array_of_players.push(new Player(msg.starting_coordinate_x, msg.starting_coordinate_y,
player_width, player_height, player_speed,msg.player_number));
is_connected = true;
$('#info').append("Connected");
}
else if(type = 'player_position')
{
console.log(msg.player_number);
updated_player = array_of_players[msg.player_number];
updated_player.point.x = msg.x_coordinate;
updated_player.point.y = msg.y_coordinate;
}
else if(type = 'request_for_existing_players')
{
console.log("number of players on request is " + msg.number_of_players);
for(var a = 0; a != (msg.number_of_players-1); ++a )
{
if(a != this_player.number)
{
array_of_players.push(new Player(-100, -100, player_width, player_height, player_speed, a));
console.log("baf");
}
}
}
};