PlayScript: Zynga Playing Clever

The need to convert Web content to mobile has exploded with users’ adoption of mobile technologies and mobile apps. And while mobile isn’t replacing the Web, content providers need to create content for both places. In the earlier days of mobile development, that meant re-writing Web apps for each mobile platform.

To combat this hugely inefficient process, a variety of compilers have been developed that generate code compatible with other platforms. For example, there are C++ compilers for Android that compile C++ source code and generate Android byte code. For C# development, there’s Xamarin. There are, however, still a few holes in cross-platform development tools. One such problem that persisted: How to create 3D games for both the Web and mobile with minimal porting effort.

Traditionally, these games were written in ActionScript for Web and then rewritten in Objective-C, Java, or C# for mobile. Despite Flash’s decline, there are still a large number of games on Facebook and elsewhere written in Flash. HTML5 isn’t quite the complete Flash replacement yet.

Zynga LogoThere are many technologies that solve a part of this problem, such as HTML5, hAxe, Native Client and others. But there are problems with incomplete coverage: Not every browser supports 3D, hAxe doesn’t support 3D and Native Client is limited to just the Chrome browser.

Zynga’s Pain and Gain

Particularly affected by this, Zynga needed a way to take its ActionScript Flash games and easily run them on iOS, Windows, Android, and other platforms. Enter PlayScript. Developed by Zynga engineers, PlayScript is a new compiler and runtime that extends ActionScript with features from C# and compiles to mobile devices.

Built on the Mono platform, the Linux equivalent of .NET, the PlayScript compiler extends the open source C# compiler employed by Xamarin to compile ActionScript and Playscript. This brings many advanced features to development. Along with easier multi-threading using tasks and async programming, this adds generics, properties, events, value types, operator overloading and LINQ. And it’s all upwards compatible with ActionScript.

Although C# 5 features are supported, the syntax of PlayScript is modeled on ActionScript. So, variable declarations use Pascal-style notation rather than C.

Here’s what it looks like:

var f:float;

var d:double;

Here’s how the same declarations would look in C/C++/C#/Java:

float f;

double d;

Since the compiler is an extension of Mono, you can have a mixture of PlayScript, ActionScript and C# files. It compiles the different files with .as, .cs and .play file extensions.

What About Stage3D?

Stage3D is a hardware accelerated, low level API for 2D and 3D, that Adobe provides with Flash. The PlayScript runtime supports a full Stage3D compatible implementation of the Flash runtime, allowing games that are Stage3D compliant to run with very minor modifications on mobile via the Xamarin/Mono runtime. Third-party libraries, such as Starling (used in Angry Birds), and Away3D can also be used without modification, as PlayScript includes a subset of the display libraries, with most features supported.

But Is It Free?

PlayScript is free and licensed under the Apache license, so just download and install it from GitHub. However, for Web development, you’ll need Adobe Flash Builder and for mobile development, you’ll need Xamarin, both of which are commercial. If you have Xamarin for mobile development, PlayScript is an alternative to MonoGame Cocos-2D, Unity and the new iOS 7 Sprite kit.

The main Web technology that PlayScript provides is Flash. There is also some JavaScript and C++ support, though it’s currently incomplete and it’s classed as experimental, so it may take a while to become stable.

Getting Started

The project has been moving very quickly and shows over 10,000 commits from 247 contributors. However, getting setup requires a bit of tinkering and some familiarity with compiling from the command line. Studio Architect and Farmville 2 developer Sean Janis has provided a comprehensive guide to getting setup on OSX with an iPhone example. There is also documentation on GitHub, as well as binaries for Windows and Mac installation.

There’s no one answer that will satisfy every development need. But, if you are doing both mobile and Web games development, PlayScript could be a great way to streamline your process. And if you just do Web development, as well as come from an ActionScript background, PlayScript may be the leg up you need to enter the mobile game space.

Comments

  1. BY Robert says:

    PlayScript is gone from GitHub now (for a number of weeks in fact). Appears that it is going closed source via Xamarin. But there has been no formal reply from Zynga or Zamarin every several inquiries.

    PlayScript :What happened to the open source version on GitHub : http://sushihangover.azurewebsites.net/post/PlayScript-What-happened-to-the-open-source-version-on-GitHub1

Post a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>