Jump to content

Trying to convert what I have to use game states...having problems.


Whack
 Share

Recommended Posts

So I have been trying to use the code from an example multiplayer project with socket.io to make my own multiplayer game. Before I go any further, however, I wanted to convert it to work with game states, which required me changing every function from this:

function onPlayerMove(playerx, playery);

to this:

onPlayerMove: function(playerx, playery);

This wasn't bad at all, but now I'm having trouble and I'm completely stuck. In the new player function, when I try to add a new player to the array of players, it calls the RemotePlayer function to create a new player, and add his data to the array. However, I'm getting an undefined error here.

 // New player        onNewPlayer: function(data) {            console.log("New player connected: "+data.id);                    // Add new player to the remote players array            playersarray.push(new RemotePlayer(data.id, game, player, playerfeet, data.x, data.y, data.playername));        },

I tracked down another multiplayer open source game created with phaser and socket.io, and using what I learned from it, I created a new javascript file which I called RemotePlayer.js, and inside of it I put the RemotePlayer function and RemotePlayer.prototype.update functions, and then I used this at the top of my play state code:

var RemotePlayer = require("entities/RemotePlayer");

now instead of an undefined error I'm getting this weird error that says "Phaser.StateManager - No state found with the key: play"

 

Can anyone offer some help for me here? I could have made lots of progress on the game today, but instead I've been stuck here because of deciding to use game states. Thank you in advance.

 

Regards,

 

Ed

Link to comment
Share on other sites

I think that state names are case sensitive, ie maybe it should be "Play" instead of "play"?

 

I've found this forum post Getting Started With Phaser very helpful in explaining and using the Phaser.state class. It has a tutorial which shows how to organise a Phaser project with states, including a basic example project.

 

And I've created a github example which also shows how to create 2 states and switch between them; see this forum post and github example here. Also, have you searched the forums? For example see this thread which has a similar question.

 

Hope that helps.  :) I'd say it's worth the hassle of reoganising your code to use states. Because it helps keeps the overall complexity down. It makes it much easier to maintain the code, isolate bugs, add features etc.
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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