Building Multiplayer Games with Construct2 and AmfPHP

  • 21 favourites


2,203 visits, 3,435 views



This tutorial hasn't been translated.


This tutorial is licensed under CC BY-NC 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

What is AmfPHP?

This free, open source Active Message Format is a Remote Procedure Call protocol library for PHP commonly called AmfPHP. AmfPHP gives a simple way to connect gamers to a centralized server – the basic building blocks of a multi-player game. AmfPHP provides binary serialization of Flash/ Flex Action Script (both 2 and 3); but, furthermore it also supports JSON, JavaScript/AJAX/HTML and even PHP data types. Everything is written for you! It eliminates the additional time to write data transfer code. If you elect to use the ‘FPCWordPress plugin’, AmfPHP turns even a simple WordPress server into a likely candidate for multi-player gaming. No messing around with socket input/output – assuming you are able to create such programs on your ISP account.

Version 2.2 – the latest release as of December 2013 – provides several ‘BackOffice’ developer tools such as a service browser, client code generator and a usage profiler. The Service Browser lets you test your server-side logic, and exposes the input parameters. You may elect to test the servers responses by ‘simple’, ‘advanced’ (i.e.: JSON or JSONP, AJAX) and even stress-test your server by selecting the ‘Call Repeater’.

The Client Generator tool is simply the best! It creates all the front-end client interface code for your game. You have several technologies from which to select:

1) Flash/Flex;

2) HTML – “This generates some simple HTML/JS code to get you started. It uses a bit of PHP just to include common stuff between the pages, but this is just for convenience.” (Quote: Silex Labs ) I examined the HTML client code generated. It is clean, easy to read and well documented jQuery and JSON JavaScript files.

3) IOS – coming soon.

4) Haxe – coming soon.

5) Android – coming soon.

6) Or write your own! This is your chance to integrate Construct2! Even if you do not adopt the AmfPHP remoting technology, it is worth your time spent generating the HTML scripts for your Construct2 projects. By doing so, you eliminate time spent re-inventing the data transfer and serialization ‘wheel’.

The Usage Profiler is the newest BackOffice tool released in 2.2. I spent so time using the stress-test features in the Service Browser; then, I navigated to this new tool. In just a glance, I learned where I needed to focus my attention. I would have spent months of my free-time trying to create such develop tool – time that could have been spent on game invention.

How Does AmfPHP Work?

AmfPHP becomes the target of information requests from players’ browsers, smart-phones or tablets. “OK!” you say,”I could just as easily use node.js or and do the same thing!” Indeed, you could, but AmfPHP is already written, and can serialize your game data is several different formats for server consumption. Your players send game state information/requests to the AmfPHP scripts on your server; AmfPHP reads those requests, calls the various functions and returns the resulting data. AmfPHP is a cleaner separation of front-end, business login and data access. Gone are those days of writing complicated server socket code, since AmfPHP performs all the “heavy lifting” for you. “Without AmfPHP, there would be one code for the web page, another for the smart-phone app, and maybe another for the tablet app. With AmfPHP, there would only be one code!” (Quote: ibid) All you write are the service classes – business logic and database connections. AmfPHP will execute those services and ensure the players receive game data in a language their browser, smart-phone, tablet understands. “AmfPHP is the best solution for creating accessible services to all terminals. Developers can focus on features unique to their (ed.: game) projects, regardless of the communication between client and server.” (Quote: ibid )

Sounds Wonderful … Show me!

You may borrow my installation @ ( ) and logon as either a ‘Guest’ or ‘Member’ with as your email and ‘test’ as your password. Everything from my Flash front-end goes through AmfPHP. The ‘member’s area’ accesses AmfPHP – which sanitizes player input; collects the player’s mySQL database records and returns a data type easily consumed as a native flash data object. I could have just as easily written this for HTML5, JSON and jQuery. AmfPHP handles all the ‘heavy lifting’ and connection processes. Here’s my server-side function which executes in 9ms:

Alternately, you might consider installing your own by downloading AmfPHP from .


  • Order by
Want to leave a comment? Login or Register an account!