📜 ⬆️ ⬇️

Haxe + OpenFL: even my grandmother can make a game under iOS!



Hi% USERNAME%! I decided to tell you how, with minimal effort, to start developing games for iOS on Haxe (in fact, not only, but I decided to limit this article to this particular platform).

For this we need:
  1. Grandma Hands. Desirable straight. More desirable from the shoulders;
  2. Mac OS X;
  3. Xcode;
  4. The idea for the game.

')
I invite everyone under the cat, even if you don’t have anything from the list.


Installation


First of all we go to the console and execute the haxe command. If suddenly for some reason we see the message

-bash: haxe: command not found 

then we run and download Haxe 3 via the link http://haxe.org/download and we don’t tell anyone else that you didn’t have Haxe;)

The next step is to install OpenFL - a cross-platform SDK that implements the Flash API on various platforms:

 haxelib setup haxelib install openfl haxelib install openfl-tools haxelib install openfl-native 


After installing the necessary libraries, it remains only to initialize OpenFL:

 haxelib run openfl setup 

Failed to load library? Watch the spoiler
If you suddenly got an error with something like this:

 Uncaught exception - load.c(237) : Failed to load library : nme.ndll (dlopen(nme.ndll, 1): image not found) 

This is not a reason for panic. Just execute the command:
 bash <(curl -s https://gist.github.com/jgranick/5658434/raw/dbdb6bbeecceeeda554a815aa8e57616540d6544/install.sh) 



Pigs




In order not to stretch the article, I will use the PiratePig example of Mac3 that comes with OpenFL, a screenshot of which can be seen above.

In order to get the same charm in ourselves, execute the following command in the terminal:
 openfl create PiratePig 


Upon its completion, a project ready for work will appear in the PiratePig folder. Run it in the simulator:

 cd PiratePig/ openfl test ios -simulator 


If everything went well (otherwise it should not be;)), an iPhone simulator will appear, which will look something like this:


After admiring the game in the simulator, the quite expected question appears: “How can I run this thing on the device?”. The answer is obvious:

 openfl test ios 


The team will launch the application on the first connected iOS device of the developer.

What's next?


Who worked with Adobe AIR remembers the horror of packaging an application for iOS. Thanks to Haxe + OpenFL, we get a standard XCode project, which can be found in the Export / ios / folder, so the process of sending the application to the App Store is similar to that for native XCode projects and has been repeatedly described, including in Habré.

FAQ


Does the Haxe + OpenFL bundle allow using native extensions?
Yes, moreover, there is already an article about it: habrahabr.ru/post/186230


Is it difficult to switch to OpenFL after Flash?
The Haxe language is very close to AS3, and the OpenFL library allows you to use the familiar Flash API, so the transition will be as easy as possible.


Will they allow my application to get into the AppStore? Cross platform - it means there is an interpreter!
Popular delusion. After compiling on iOS, you get native C ++ code.


Flash API? What if I want to use OpenGL?
Despite the fact that OpenFL is close to the Flash API, it does not deprive you of all the benefits of native development. Moreover, in OpenFL and so everything is rendered through OpenGL. Click here for an example of using OpenGL.


Are there any projects written in OpenFL in the App Store?


Conclusion


OpenFL, as a library of Haxe, has great potential for cross-platform development. In this article, I showed how to use it when developing for iOS, but at the same time, this game can also be run on Android, HTML5 or Flash , and it will work the same everywhere ( Full list of supported platforms ). Try, experiment and share your experience!

Source: https://habr.com/ru/post/186520/


All Articles