Jump to content

Weird sprite positioning issue.


Sapper
 Share

Recommended Posts

I'm creating a multiplayer game with Phaser and using my own PHP socket and I can't seem to get the client side character to position correctly on the screen.

function create() {    websocket = new WebSocket(wsUri);         //  Modify the world and camera bounds    game.world.setBounds(-1000, -1000, 2000, 2000);    land = game.add.tileSprite(0, 0, 800, 600, 'earth');    land.fixedToCamera = true;        //create player and add his walking animations    player = game.add.sprite(150, 150, 'dude');    player.scale.x = .4;    player.scale.y = .4;        //  We need to enable physics on the player    game.physics.startSystem(Phaser.Physics.P2JS);    game.physics.p2.enable(player);    player.body.collideWorldBounds = true;    players = [];        game.camera.follow(player);    game.camera.deadzone = new Phaser.Rectangle(150, 150, 500, 300);    game.camera.focusOnXY(150, 150);    player.name = '';    player.dname = game.add.text(player.x, player.y, "guest", { font: "12px Arial", fill: "#800028", align: "center" });    cursors = game.input.keyboard.createCursorKeys();    setEventHandlers();}function addPlayer (uname, startX, startY) {    players.push(new AddPlayer(uname, startX, startY, player, game));}function AddPlayer (uname, startX, startY, player, game) {    var x = startX;    var y = startY;    this.game = game;    this.health = 3;    this.player = player;    this.alive = true;    this.player = game.add.sprite(x, y, 'players');    this.name = uname;    this.player.scale.x = .4;    this.player.scale.y = .4;        this.player.dname = game.add.text(x, y, this.name, { font: "12px Arial", fill: "#330088", align: "center" });        console.log('Added player to client: '+this.name);    this.lastPosition = { x: x, y: y }}; 

Basically, in simple terms:

 

player = game.add.sprite(150, 150, 'dude');        in the create() function

 

and:

 

this.player = game.add.sprite(150, 150, 'dude');      in the addPlayer(); function (which is populated by the server at a starting point of 150, 150) yields two completely different locations on the map as evidenced by:

 

2luqv6w.png

 

Literally, I'm going crazy over how such a phenomenon could happen. Any ideas?

 

 

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...