What I have on the serverside (using Microsoft Visual Studio) is
- Code: Select all
// This method is called whenever a player joins the game
public override void UserJoined(Player player) {
// Create a Player
Broadcast("createPlayer", player.Id);
// Create init message for the joining player
Message m = Message.Create("init");
// Tell player their own id
m.Add(player.Id);
// Send init message to player
player.Send(m);
}
Then in my main .as file I have the following code:
- Code: Select all
connection.addMessageHandler("createPlayer", function(m:Message, id:int){
createPlayer()
})
To get the message from the server to create the player and the createPlayer() function looks like this:
- Code: Select all
private function createPlayer():void{
// Create Player
var playerMovieClipVar:PlayerMovieClip = new PlayerMovieClip
//Add listener dispatched when the player is moved
playerMovieClipVar.addEventListener(Event.CHANGE, function(e:Event){
var target:PlayerMovieClip = e.target as PlayerMovieClip;
//Inform server that the player was moved
connection.send("movePlayer",target.Id, Math.round( target.x ), Math.round( target.y ))
})
//Add player to stage
addChild(playerMovieClipVar)
}
In the PlayerMovieClip.as I have some code that simply makes it go form the top of the screen to the bottom.
The result of this adds the player to the stage but with a few problems.
1. The player that joins can not see any of the previous playerMovieClips of the previous players that joined before them.
For intsance player one sees its movieclip, player twos movieclip, and player threes movieclip
player two sees its movieclip and player threes movieclip
player three only sees its movieclip.
2. The movement looks ok but if I try to make it so the movieclips are contorted with the arrow keys it causes compiler errors that I will explaine if I can get problem 1 fixed.
Any help would be greatly appreciated, I hope the information provided makes sense.