Cocos2d-x JavaScript Networking Tutorial Series

  • efares
    Likes 0

    This is awesome! Is it like making a multiplayer game?

    I would love to see a tutorial on how to build a multiplayer game with Cocos2d-x Js using node.js and socket.io :)

  • Sonar Systems admin
    Likes 0

    It provides a good foundation for building multiplayer games.

  • adesuluhn
    Likes 0

    more cocos2d-x animation control for connect in xcode project to cocostudio like setting up from splashscreen, start screen,etc will be great!


  • Sonar Systems admin
    Likes 0

    Yh it would.

  • mahesh
    Likes 0

    Sir,

    Have you written any tutorial about using socket.io with android and ios?

  • mahesh
    Likes 0

    Sir,

    I can make it work for web version by including socket.io.js
    I don’t have a server and i haven’t checked with android. But i guess it wont work.

    There should be a cocos2dx javascipt module. I am not able to find the implementation.
    Can you please guide me?

    In js test, var SocketIO = SocketIO || windows.io;

    This SocketIO must be a cocos2dx variable. If i try this line, I am getting undefined error or something.

  • Sonar Systems admin
    Likes 0

    We have never used SocketIO so don’t know much about it but try posting on the Cocos2d-x forums as I am sure many other users have used it/

  • tjjoss
    Likes 0

    Hi! First of all, thanks for the great resources you produce, your videos are the best.

    I have a question relating the POST request. I implemented the code provided to communicate to a web page (where my cocos game is hosted) and I'm having a couple of problems:

    1. The webpage receiving the post request does not reflect the changes that are supposed to be shown when I call it. When I click elsewhere (ie, another section of the webpage) the changes are correctly shown. So it's like the cocos2d game gets the http response instead of the browser, and so the changes are not shown (even though they have been applied). 
    2. And this might be related to the previous question, the communication was working fine over http but when I switched to https, the webpage doesn't seem to be responding to my requests even though I get a 200 response back along with the complete html response. This means that now, even if I click on other parts of the webpage, the changes are not being applied. Any help would be greatly appreciated.

    To make it a little bit more clear. This is the code I’m using:

            var xhr = cc.loader.getXMLHttpRequest();
            var url = "/?add-to-cart=8&ref=";
            url += conf;

            xhr.open( "POST", url );
            xhr.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
            xhr.send();
                                          
            xhr.onreadystatechange = function ()
            {
                if ( xhr.readyState == 4 && ( xhr.status >= 200 && xhr.status <= 207 ) )
                {
                    var httpStatus = xhr.statusText;
                    cc.log(sTime() + " [AnimationLayer] Status: " + httpStatus);

                    var response = xhr.responseText;
                    cc.log(sTime() + " [AnimationLayer] Response: " + response);
                }
            }

     

    As you can see, nothing fancy, it’s practically what you showed on your video. I’m calling the "/?add-to-cart=8&ref=" url (over https) with some parameters in the query string (ie the item to add to the cart) . The log output of that code is: 

    12:11:19 [AnimationLayer] Status: OK
    12:11:19 [AnimationLayer] Response: <!DOCTYPE html>
    <html class="html" lang="en-US">
     <head>

      <script type="text/javascript">
       if(typeof Muse == "undefined") window.Muse = {}; window.Muse.assets = {"required":["museredirect.js", "jquery-1.8.3.min.js", "museutils.js", "jquery.watch.js", "index.css"], "outOfDate":[]};
    </script>

    So, I’m definitely getting a response, and it seems valid, but the browser is not showing any of the changes it supposedly received (ie, a new item added to the cart). 
    What’s wrong then?
  • Sonar Systems admin
    Likes 0

    Could you post this as a separate question.

  • tjjoss
    Likes 0

Login to reply