PlayScript

Original author: Zynga
  • Transfer
Translator's note: a week ago, Zynga opened the source for a project that simplifies the transfer of games from Flash to mobile platforms. Since there are a lot of people on the hub who write games on flash, or for mobile platforms, I present you the translation of the text from the page of this project. It is likely that you will want to use it in your development.

What is PlayScript?


PlayScript is an open source project, which is an ActionScript-compatible compiler and a Flash-compatible runtime that runs on Mono .NET and is designed to create mobile applications using MonoTouch and Mono for Android. The combination of Adobe FlashBuilder for creating web applications and Xamarin Studio for mobile will allow you to develop multi-platform applications using all the advantages of IDE data, as well as with the ability to access the native API on mobile platforms.


The PlayScript compiler can also translate its code in C ++ and JavaScript (similar to Haxe), which allows you to create web applications that do not require Flash, as well as native applications for PC and mobile (with some restrictions). Note: JS and C ++ are currently under experimental development.

In addition to supporting ActionScript, the PlayScript compiler also supports a new language - PlayScript - which is a mixture of C # and ActionScript. This new language supports all C # features, including:
• Generics
• Properties
• Events
• Value types
• Operator overloading
• Asynchronous programming
• LINQ

Despite this, the language is backwards compatible with ActionScript. PlayScript can be used to create web and mobile applications (via JavaScript and Mono). Existing Flash applications can be easily converted to PlayScript by simply renaming files from .as to .play and fixing some problems associated with more stringent syntax and semantics of the new language.

In addition, the PlayScript runtime provides full Stage3D support, allowing you to port games to phones with very little change. Part of the display library has also been implemented to support third-party Stage3D frameworks such as Starling, Away3D, and Feathers.

PlayScript provides a complete set of tools for creating and running ActionScript games on mobile phones using Mono and on the web using Adobe Flash or JavaScript / HTML5.

How is PlayScript implemented?


The PlayScript compiler is implemented as an additional preprocessor for the Mono MCS compiler. Installing the PlayScript version of Mono will allow you to compile all three languages ​​(C #, ActionScript and PlayScript) by simply adding files with the .cs, .as and .play extensions on the MCS command line.

In the same way, in the Xamarin Studio IDE, on the framework version selection page, you can select “PlayScript Mono”, which allows you to add .as and .play files to any C # project and compile them using MonoTouch or Mono for Android. ActionScript code can directly call C # code, and vice versa.

How is Stage3D implemented?


PlayScript includes two libraries: PlayScript.Dynamic_aot.dll, and pscorlib.dll, which implement the runtime and Stage3D via OpenGL. Links to these libraries in your project will allow you to run existing code using Stage3D without modification.

Current status


The PlayScript and ActionScript compiler is quite stable at the moment (given that it is built on the basis of mature Mono), but there is still some ActionScript functionality that has not been implemented. Work is underway to address these outstanding issues and provide full compatibility with ActionScript.

ActionScript Support

• Dynamic classes are compiled, but not yet implemented.
• The [Embed] tag has not yet been implemented.
• Singleton pattern using the guard class is not supported (using a private parameter in the public constructor)
• Static and non-static members with the same name are not supported.
• Class and package level instructions are not supported.
• A variety of minor errors.

PlayScript Support

• Unsafe code is not supported (conflict using * character in ActionScript).
• Some problems with multidimensional arrays.
• Translation in JavaScript and C ++ is experimental.

Runtime support

• Much work has been done to support Stage3D and implement AGAL through HLSL.
• Starling and Away3D frameworks are fully functional.
• Very little work has been done on the net library and other kernel libraries.

How to install PlayScript?


You can download the current binaries here:

Mac OSX 0.1.2 (Mono 3.0.8)

Windows: (Coming)

The package includes the Mono SDK, tools and libraries. To use the framework, install Xamarin Studio, and follow the instructions (see below) to make the PlayScript mono framework the default framework.

Assembly from source

Since PlayScript is part of Mono and MCS, you can use the appropriate instructions from Xamarin to build it.

Mac:

www.mono-project.com/Compiling_Mono_on_OSX

Windows:

www.mono-project.com/Compiling_Mono_on_Windows

In addition, the base libraries pscorlib.dll and PlayScript.Dynamic.dll (excluding Stage3D) will be compiled and added to the GAC in the final Mono installer . To use the "monotouch", "monomac" or "monoandroid" versions of these libraries, use the .csproj files in the "mcs / class" folder in the repository.

How to use PlayScript in Xamarin Studio?


• Build Mono according to the instructions. Use --prefix = / Users / myname / playscript-mono-inst to install the framework in a convenient place on your hard drive.
• Open Xamarin Studio, and select “Preferences”.
• Select the “.NET runtimes” tab.
• Click on the “Add” button and select the folder where the PlayScript mono framework is located.
• Click the “Set as Default” button.
• Restart Xamarin Studio.

You should now be able to add .as and .play files to your project and compile them.

Features:


Performance

• Use of "unsafe" code.
• Direct interaction with machine code (cocos2d-X, Page44, etc.).
• Optimized compiler for generating JavaScript.
• Ability to translate in C ++ with a minimum application size and with minimal overhead to launch.

Advanced Support Tools

• Full support for tools, including syntax highlighting and Intellisense in the MonoDevelop IDE.
• Debugging source code on all platforms (FlashBuilder for Flash).
• Fast compilation in Release.

Full API support

• Full support for iOS and Android APIs through MonoTouch and Mono for Android.
• Full support for the Windows / MacOSX API.
• Full integration with UI Builder (iOS) and Android GUI Builder through Xamarin Studio.

Differences between PlayScript and ActionScript

• PlayScript supports most of the features of C # 5.
• PlayScript requires a semicolon after the end of the instructions.
• PlayScript uses visibility blocks for variables.
• PlayScript requires the use of break in a switch statement.
• PlayScript supports generics using AS3 syntax (. <>) Using C # functionality.
• PlayScript supports properties using the "property" keyword.
• PlayScript supports indexers and operator overloading using the keywords “indexer” and “operator”.
• PlayScript implements namespaces in AS3 by converting them to .NET namespaces.

Differences between PlayScript and C #

• PlayScript requires the use of the overload keyword for overloaded methods.
• PlayScript does not support the using statement.
• The PlayScript browser does not support the checked and unchecked statements.
• PlayScript does not support unsafe code (although support will be added in the future).
• In PlayScript, you cannot directly access the properties of the base Object (ToString (), GetType (), GetHashCode ()) until you cast it to System.Object. However, using this approach will make it impossible to translate your code in C ++ or JavaScript.

License


This Zynga project is released under the Apache license.

PlayScript sample code


// Basic types
var b:byte;
var sb:sbyte;
var s:short;
var us:ushort;
var i:int;
var u:uint;
var l:long;
var ul:ulong;
var f:float;
var d:double;
// Conditional compilation
#if DEBUG
#else
#endif
// Fixed arrays
var a:int[] = new int[100];
// Properties
public property MyProperty:int {
   get { return _myInt; }
   set { _myInt = value; }
}
// Events
public event MyEvent;
// Delegates
public delegate MyDelegate(i:int):void;
// Operators
public static operator - (i:int, j:int):int {
}
// Indexers
public indexer this (index:int) {
   get { return _a[index]; }
   set { _a[index] = value; }
}
// Generics
public class Foo. {
    public var _f:T;
    public function foo(v:T):void {
    }
}
// Async
async function AccessTheWebAsync():Task. 
{ 
    var client:HttpClient= new HttpClient();
    var getStringTask:Task. = client.GetStringAsync("http://msdn.microsoft.com");
    var urlContents:String = await getStringTask;
    return urlContents.Length;
}

Also popular now: