Gandalf_life Posted January 12, 2017 Share Posted January 12, 2017 Hello there, i'm totally new to phaser. I need its power for a project but i'm pretty lost for something. Indeed, i wan't to create a sort of scenario like : "Player 1 moves" "Player 1 sends an arrow" "Player 2 moves" "Player 2 heals" So i don't have to interact with any inputs right now. The problem is in my update function, i'm moving the characters but it's doing everything simultaneous : player1.moveTo(38, 76); player2.moveTo(380, 304); Where moveTo is : Player.prototype.moveTo = function(x, y) { this.moving = true; //player a position x, y. Je veux le faire bouger à x1, y1. if(this.player.isoX < x) { this.moveRight(); } else if(this.player.isoX > x) { this.moveLeft(); } if(this.player.isoY < y) { this.moveUp(); } else if(this.player.isoY > y) { this.moveDown(); } if(this.player.isoX == x && this.player.isoY == y && this.moving == true) { this.moving = false; this.addTurn(1); } } and finally, a moving function Player.prototype.moveRight = function() { this.player.isoX += this.moveSpeed; } this is an example of functions that can be called during the scenario. I tried to create a turn variable to make player1 plays, then players2 when it's turn 2, but it's still doing simultaneous actions for each player (like moving and attacking at the same time) Sorry for this first entry in the phaser world, and thx for answers hope Link to comment Share on other sites More sharing options...
Gandalf_life Posted January 12, 2017 Author Share Posted January 12, 2017 dont blame me, i need to use eval in my case function play(){ if(eval(scripts[actionToPerform]) == true) { eval(scripts[actionToPerform]); } else{ actionToPerform += 1; } } Link to comment Share on other sites More sharing options...
squilibob Posted January 13, 2017 Share Posted January 13, 2017 Make a queue, add player movements to the queue and use the update function to keep track of the current player. queue = []; queue.push({player:player1, x:38, y:76}); queue.push({player:player2, x:380, y:304}); function dequeue() { if (player1.moving || player2.moving) return; // if any player is moving then nothing will be dequeued if (queue.length) { // if there is something in the queue var current = queue.shift(); // get the next item current.player && current.player.moveTo(current.x, current.y); // checks if player exists and then sends the x,y to its own moveTo method } } you then only need to use in your update: dequeue(); Link to comment Share on other sites More sharing options...
Recommended Posts