I'm very new to nodejs and socket.io. I'm trying to create a simple multiplayer card game in real time. my problem right now is I can't get the player's view to display on the correct div from player's perspective. example is.. I want my playing area to display at the bottom box and my opponent to display on top box and same goes with my opponent's viewer. he will see himself on the bottom div and sees me on the top div. How do u get that effect to work?
client
<div class='top'></div>
<div class='bottom></div>
<script>
var socket = io();
socket.on('playerinfo', function(data){
$('.top').html(data[0]);
$('.bottom')html(data[1]);
});
</script>
server
var players = [];
io.on('connection', function(socket){
//player is given 'P' with random number when connection is made to represent username
socket.name = "P" + Math.floor(Math.random() * (20000));
players.push(socket.name);
io.emit('playerinfo', players);
}
Also it would be great if you can point me to a tutorial or blog related to this. thank you.