Forum General Easy Tutorial Haxe with PlayerIO / Yahoo Games network

Any issues or discussions relating to Flash development are welcome here.

Easy Tutorial Haxe with PlayerIO / Yahoo Games network

Postby archipdev » September 6th, 2014, 12:09 pm

Hi

This is how I made playerio / yahoo games network works with haxe.

1 – How to get the library.swf
Download the SDK and go to "\Flash\NewGame\Flash"
Rename PlayerIOClient.swc -> PlayerIOClient.zip
Extract the zip to get the library.swf

2 - How to generate hx classes
Copy library.swf to the desktop and rename it librarypio.swf
Open a terminal (windows+R -> cmd -> OK)
Go to the desktop (type cd Desktop)
Type c:\HaxeToolkit\haxe\haxe.exe -swf nothing.swf -swf-lib librarypio.swf --no-output --gen-hx-classes
If it worked, there is a new folder on your desktop called hxclasses containing a folder called playerio.

3 - Create the client
Create new project in FlashDevelop.
Copy the playerio generated just before in "src".
Copy librarypio.swf in "assets"
In application.xml add this line : "<compilerflag name="-swf-lib assets/librarypio.swf" />" just before "</project>"
Create class in "src" called "LibraryPlayerIO"
Replace content of the class by "package ; @:file("assets/librarypio.swf") class LibraryPlayerIO extends flash.utils.ByteArray { }"
Open Main.hx
add this : import playerio.*;
add this code at the end of the init function :
Code: Select all
var playerio_loader = new Loader();
playerio_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
playerio_loader.loadBytes(new LibraryPlayerIO());


add those functions
Code: Select all
function onComplete(ev:Event){
         PlayerIO.connect(
            stage,                        //Referance to stage
            "[Enter your game id here]",         //Game id (Get your own at playerio.com)
            "public",                     //Connection id, default is public
            "GuestUser",                  //Username
            "",                           //User auth. Can be left blank if authentication is disabled on connection
            null,                        //Current PartnerPay partner.
            handleConnect,                  //Function executed on successful connect
            handleError                     //Function executed if we recive an error
         );   
      }
      
      private function handleConnect(client:Client):Void{
         trace("Sucessfully connected to player.io");
         
         //Set developmentsever (Comment out to connect to your server online)
         client.multiplayer.developmentServer = "localhost:8184";
         
         //Create pr join the room test
         client.multiplayer.createJoinRoom(
            "test",                        //Room id. If set to null a random roomid is used
            "MyCode",                     //The game type started on the server
            true,                        //Should the room be visible in the lobby?
            {},                           //Room data. This data is returned to lobby list. Variabels can be modifed on the server
            {},                           //User join data
            handleJoin,                     //Function executed on successful joining of the room
            handleError                     //Function executed if we got a join error
         );
      }
      
      
      private function handleJoin(connection:Connection):Void{
         trace("Sucessfully connected to the multiplayer server");
         
         //Add disconnect listener
         connection.addDisconnectHandler(handleDisconnect);
               
         //Add listener for messages of the type "hello"
         connection.addMessageHandler("hello", function(m:Message){
            trace("Recived a message with the type hello from the server");         
         });
         
         //Add message listener for users joining the room
         connection.addMessageHandler("UserJoined", function(m:Message, userid:UInt){
            trace("Player with the userid"+ userid+ "just joined the room");
         });
         
         //Add message listener for users leaving the room
         connection.addMessageHandler("UserLeft", function(m:Message, userid:UInt){
            trace("Player with the userid"+ userid+ "just left the room");
         });
         
         //Listen to all messages using a private function
         connection.addMessageHandler("*", handleMessages);
         
      }
      
      private function handleMessages(m:Message){
         trace("Recived the message" + m);
      }
      
      private function handleDisconnect():Void{
         trace("Disconnected from server");
      }
      
      private function handleError(error:PlayerIOError):Void{
         trace("got" + error);

      }


Put your game ID where it is required.


Launch the server
Compile the client.
It works ! Or so I hope
archipdev
 
Posts: 28
Joined: September 6th, 2014, 10:35 am

Re: Easy Tutorial Haxe with PlayerIO / Yahoo Games network

Postby kbhattArooga » November 28th, 2014, 11:36 am

Hi,

The client side example is very helpful for someone new; do you have something similar for setting up the server at bare minimum.

I'm not from the backend side so am stuck as I cannot configure my canvas; it keeps saying Game Canvas not supported.

Some help or direction would be really helpful.
kbhattArooga
 
Posts: 1
Joined: November 28th, 2014, 9:22 am


Return to General



cron