How do you make a mutiplayer game in phaser:
#Phaserjs
#phaser
#socket.io
This is private :/:
This is all i have so far another bug with the player s that when you move the piont to mouse function get wonky :(>
(this is a top-down shooter game.)
//vars
var mouse;
//initialise global variables
var player;
var obstacles;
var cursors;
var yLimit;
var xLimit;
class SceneTest extends Phaser.Scene {
constructor() {
super ({key:"SceneTest"});
}
preload() {
this.load.image('player','assets/repl.png')
this.load.image('obstacle','assets/obstacle.png')
this.load.image('floor', 'assets/floor.png');
}
create (){
let background = this.add.image(0, 0, 'floor').setScale(6);
background.x = background.displayWidth / 2;
background.y = background.displayHeight / 2;
xLimit = background.displayWidth; //the player cannot go beyond these x and
yLimit = background.displayHeight; //y positions
player = this.physics.add.sprite(0, 0, 'player'); //create the player sprite
player.setScale(0.3); //make it appear smaller
console.log("Player is spawned at"+ player.x,player.y)
cursors = this.input.keyboard.createCursorKeys(); //creates an object containing hotkeys
this.cameras.main.setBounds(0, 0, xLimit, yLimit);
obstacles = this.physics.add.staticGroup(); //create group for obstacles
obstacles.create(800, 600, 'obstacle');
obstacles.create(950, 800, 'obstacle');
this.physics.add.collider(player, obstacles); //collision detection between player and obstacles
//for mouse position
mouse = this.input;
}
update (){
//angle between mouse and player
let angle = Phaser.Math.Angle.Between(player.x,player.y,mouse.x,mouse.y);
//rotation player
player.setRotation(angle+Math.PI/2);
if (cursors.left.isDown && player.x >= 0) {
player.VelocityX =- 200; //go left
}
else if (cursors.right.isDown && player.x <= xLimit) {
player.setVelocityX(200); //go right
}
else {
player.setVelocityX(0); //don't move left or right
}
if (cursors.up.isDown && player.y >= 0) {
player.setVelocityY(-200); //move up
}
else if (cursors.down.isDown && player.y <= yLimit) {
player.setVelocityY(200); //move down
}
else {
player.setVelocityY(0); //don't move up or down
}
this.cameras.main.centerOn(player.x, player.y); //centre camera on current position of player
}
}
and yeah i have never used socket before soo uh… yeah… (i have VERY little expericne w/ socket)