Yet-another Multiplayer Demo (with capx)

0 favourites
From the Asset Store
Demo Game Multiplayer Online with member registration system
  • Update 9/22/2012: Please try JohnnySheffield new plugin at http://www.scirra.com/forum/plugin-zack0wack0s-socketio-mod_topic56503.html. He updated the plugin to work with minify and other goodness. Thank you.

    Based on the work of Zack0Wack0, I was able to modify a little bit his excellent socket.io plugin and created a small top-down shooter game.

    To download the demo and the modified version of the socket.io plugin, please go here and download the "socket-io-mod.zip" file.

    Before you can use the plugin and the example, please install node.js and socket.io as Zack0Wack0 explained in his post. If you are using Windows, I strongly suggest that you open the CMD, cd to C:\node_modules (create that folder is not present) and run the "npm install socket.io" from there. It seems that Node.js has "C:\node_modules" hardcoded as one of the paths to find installed modules.

    Instructions

    Once you install node.js and socket.io, you can CD into the folder that contains example_server.js and type "node example_server.js" in the commnad prompt. The server will run listening for connections on port 8099.

    Open the capx and run it, make sure the "ChooseServer" layout is the 1st to run.

    For server address you can enter the IP of the computer that is running the server, if it is the same computer, you can enter 127.0.0.1.

    Enter 8099 in the server port and click Connect.

    If you run the capx in another computer, make sure you enter the appropriate IP address of the computer running the node.js server.

    You can also try to run two separate instances of the game in the same computer by just opening two broser windows and going to the address where you game is (default for preview localhost:5000).

    I have only tested it in Chrome and Windows. Also, if you want to export the project, avoid checking "minify" for some reason I can't get it working with that, I think Zack0Wack0had the same problem.

    You can watch a video of the sample game in a LAN here

    Update 4/19/12:

    I wrote a new post in my blog on how the multiplayer demo works in Construct2:

    http://jptarqu.blogspot.com/2012/04/how-to-create-online-multiplayer-html5.html

    I also uploaded a new video showing an iPad connecting to the game:

    Subscribe to Construct videos now
  • Good job! :D

  • Great!!! But you have to type a IP and a port number so practically is it usable in a game? If you want to search for a game ect the use would need to know there IP adress right? Or can we find that out within c2?

    I just want to know a practical way of using this in a game.

  • If you want C2 to display a list of available servers, i.e. a lobby, you would have to code the display logic in C2 and then store the list of servers in a server where anybody can query the list.

    One way of accomplishing that is to create a server side app (php, asp.net, gae, etc) that receives http POST messages from c2 clients who want to host a game. The server side app will store the name of the server and its public ip.

    the servers side app would also accept Get messages from c2 clients who want to retrieve the list of available servers. The server side app would pull the list from its database. Because the list will have the ip of the servers, you can add logic to c2 to use that ip when the user chooses the server and clicks Connect.

    There are many ways of implementing lobbys, but i think the above would be the easiest for c2 users.

  • Unfortunately I am not so good with server side scripting like that so I guess multiplayer is something I cannot do. <img src="smileys/smiley6.gif" border="0" align="middle" />

  • If you want C2 to display a list of available servers, i.e. a lobby, you would have to code the display logic in C2 and then store the list of servers in a server where anybody can query the list.

    Thanks, juantar, for a good overview of how multiplayer games can be made available over the internet (as opposed to over a LAN).

    For those interested in the nuts and bolts of implementing a lobby server, here's a good practical article. To quote from the intro explanation of how a lobby functions:

    "A lobby is in essence a collection of players and a collection of games. Each player may be in one or more games, and each game may contain one or more players. Players should be able to create, join, leave and start games, and they should be able to see which games are already available and which players are in the 'room', although this is simply a case of allowing the UI to see that data. A lobby should also fire events when players join or leave the server, or the state of a game changes (i.e. a new player joins, or it moves from setup to 'in play'), so that a UI can know when to update."

  • I get making the visual side of things, I meant how can I find a game, for example user loads up game, goes into multiplayer mode. Somehow we get his IP address then we need to find a random ip adress of another user and somehow connect the two right? But how can I do this..?

    Can the game be hosted on a web server? Or does the multiplayer only work locally?

    Thanks.

  • Somehow we get his IP address then we need to find a random ip adress of another user and somehow connect the two right? But how can I do this..?

    Through a game lobby. See my and junatar's previous posts.

    Can the game be hosted on a web server?

    Yes, indeed. That's what the game lobby does - connects you with a server hosting a game (and connecting you with other players of that game).

    <EDIT> To be more precise, the game is split into a component that runs locally and a component that runs on the server, managing the interactions between players.

    For example, in a single player FPS game running locally where your enemies are created and controlled by the (Construct 2) code, in a multiplayer game, where your enemies are other players, their actions have to be communicated by the server component of the game.

  • Velojet, Thanks for the help. I think im getting there in terms of understanding. But the multiplayer needs to run of node.js right? can a webserver run node.js?

    I think I need a example, would that be possible? <img src="smileys/smiley1.gif" border="0" align="middle" />

    Thanks.

  • Every time I type "npm install socket.io" it just puts

    ...

    [FIXED]

    Disregard me xD

  • ... I think im getting there in terms of understanding. But the multiplayer needs to run of node.js right? can a webserver run node.js?

    Node.js is one means of making a server, but multiplayer gaming servers have been around for a long long while before node.js came on the scene.

    ... I think I need a example, would that be possible?

    I'm not sure what you mean by an example, but here's an article on building a multiplayer PC gaming server (using free servers that aren't node.js based), that might help to expand your understanding (including giving you an idea of the complexities <img src="smileys/smiley6.gif" border="0" align="middle"> )

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi I followed the step but. when I run the. capx introduce the correct ip and port and nothing happens. <img src="smileys/smiley5.gif" border="0" align="middle" />

    result server= info- handshake authorized 881214523216515

    result client= text in the textbox

  • Hi I followed the step but. when I run the. capx introduce the correct ip and port and nothing happens. <img src="smileys/smiley5.gif" border="0" align="middle" />

    result server= info- handshake authorized 881214523216515

    result client= text in the textbox

    i had the same problem when i tried to use the ip for the lan network for eg 192.168.1.86 it doesn't work but when i tried 127.0.0.1 and open the game in different browsers it worked :S

    any solution to this?

    thank you

  • chromstruct and noranka: Interesting... what browsers are you using? The "info- handshake" message that you get, where do you see it?in the console or the screen?

    Also, I uploaded a new version with a small fix in the example server, can you please re-download the plugin.

    Thanks

  • i use firefox and chrome to test the game

    when i entered 192.168.1.86 and the port number the textbox just disappears and nothing happens

    i'll try the new plugin thanks

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)