Help on the concept of making stages/rooms/levels in Haxe!

Helloooo guyz :slightly_smiling:

I have been making games for a long time but only using engines :stuck_out_tongue: and recently I started learning OpenFl to make games for both flash and html5 and I am learning it and getting comfortable with it slowly but one concept that still puzzles me is of different views/levels in openFL, how would one go about making a menu, a level, level select etc. ?

I searched for it, looked into haxeflixel states system which gave me some idea but still not very clear :frowning: Please any easy explanation of the whole concept would be very very helpful! I am having this trouble since in game engines we just press a button and a new level is ceated :stuck_out_tongue:

The only thing I can think of myself is to like for example manually check for like a keypress and then manually delete all objects relating to gameplay and create new menu buttons to show menu, is this a good way to do it ?

Thanks a lot and please help :slight_smile:

OpenFL, just like Flash, has a Display List hierarchy, versus traditional game engines using loops, drawing and update sequences, which means that the content pipeline favours object-oriented style programming.

The most common container class in OpenFL is the Sprite class, which offers the most flexibility in the framework. Using the addChild function, you add other Sprite's or any object that extends from DisplayObject. Basically, if an object extends DisplayObject, it can be added to the Display hierarchy, and thus rendered. Rendering is done automatically by OpenFL depending on what target you use. On C++, Neko and other native targets, OpenGL is used. In HTML5, unless the -Dwebgl define is used when using the build command, it uses the Canvas with fallback to DOM, or otherwise WebGL. All other targets are unknown to me, some use the Cairo renderer which was an addition starting with OpenFL 3.0.

One thing to note is that OpenFL is not an engine, it’s more of a framework. Engine’s provide a set of utilities that can help make games easier, such as in-built rendering engine that support simulation regions that optimise performance for large levels. Frameworks, on the other hand, often just provide a basic set of low level APIs that help toward a specific goal, in the case of OpenFL it would be to make video games.

Depending on what type of game you want to make will depend on what tool is best to use. For large, open world role-playing games, first person shooters and platformers, I suggest sticking to the engine’s that you use, because they will have tools you will need without having to write them yourself. For smaller engine-like projects, such as visual novels, or any basic game mechanic for that matter, OpenFL is a good choice.

Having used OpenFL for a little over a year, and Flash for two years previous to that, OpenFL is one of the most fleshed out of the frameworks that currently exist with Haxe. There are attempts to make alternatives, such as Kha which is even more low level than OpenFL, and consequently performs slightly faster. They all have their merits. But definitely research each alternative before deciding to make a game, because you could choose an engine and not use 90% of the features for a visual novel, versus using OpenFL to create an RPG when HaxeFlixel has the collision, grouping and state systems you need to make a tile-based game.

But getting back to the point, when creating object’s in OpenFL you will normally use Sprite’s to contain lots of different objects.

Text can be displayed using the TextField class, and images can be displayed using the Bitmap class.

When making the switch between scenes and/or levels, normally these are approached by simply removing one child and replacing it with another. You can use scene transitions and loading screens for more visual effect, but then I would be delving into the realms of tutorials.

With levels, you will generally have some kind of data-oriented model that describes the scene, and you will generally have a class that simply takes that data and arranges a series of Sprite’s, Bitmap’s and/or Text onto the screen. There are lots of ways to approach this, but the most common are the use of XML/JSON files that describe animations, tile-maps, items, and perhaps more.

You can use SimpleButton to create the effect of a button, but adding Text may remove the desired effect, so I would recommend creating a separate class if you are thinking of placing text ontop, or just create a graphic of each button you need.

HaxeFlixel’s state system is rather interesting. Instead of an active/inactive screen management system, you instead use FlxG.switchState where you pass a class type that extends FlxState, and FlxG does all the underlying rendering required.

There are a lot of tutorials on OpenFL and Flash, and often if there is not a tutorial or help with OpenFL for a specific situation, there may be a solution in Flash so always check both sides.

I also have my own tutorials, starting from explaining how the build system in OpenFL works to using the Graphics component, and then moving onto basic movement and more. You can view them here.

I did not do a tutorial on sound, but that is rather simple to use so doing a video tutorial on it is rather overkill. Alternatively, there are other tutorial resources out there, including haxecoder.com, haxeresource.meteor.com among many others.

I hope this helps!

1 Like

Thanks a tons! Yes!!! I have already been through some of your videos they are great!