I am currently in the process of developing a game using Phaser IO and SignalR along with jQuery. The server provides me with a list of players, each containing an ID and Name. I then create a text field for each player which I plan to later manipulate based on the number of votes that specific player has received. However, I am unsure how to reference the dynamically created text objects.
I am open to any new ideas or suggestions.
var game = new Phaser.Game($window.innerWidth, $window.innerHeight, Phaser.Auto, 'gameCanvas');
var dayState = {
preload: function () {
// Preloaded stuff
},
create: function () {
var world = game.world;
// Get list of players alive in the game from server
var players = // Server call to retrieve list of players
// Add player
for (var i = 0; i < players.length; i++) {
var currentPlayer = players[i];
// Display player name
game.add.text(world.width - 225, y, currentPlayer.Name);
// I WANT TO UPDATE THIS UPON CALLBACK
game.add.text(world.width - 175, y, 0)
// Vote button
game.add.button(world.width - 50, y + 2, //preloaded texture for button, voteFunction, currentPlayer.Id , 2, 1, 0);
}
}
};
game.state.add('DayState', dayState);
game.state.start('DayState');
function voteFunction() {
// Posts vote to server
};
function voteReturnedFromServer(amount){
// Server calls this function (SignalR)
// This is where I want to update text element created above with data from SignalR
// Update text with callback data "amount"
};