Repository navigation
Code Structure
Stencyl's engine is written on top of NME, a popular Haxe library that replicates the Flash API. In order to understand the engine, it helps to know Haxe or ActionScript 3.
Stencyl is heavily reliant on Box2D, a popular physics library used in many games.
Here's what you need to know to understand the Stencyl engine.
- Haxe or ActionScript 3
- Knowledge of Box2D is extremely helpful if working with physics
- Basic knowledge of Flash API's fundamentals like the display tree, sprites, etc.
Developing in Haxe is still somewhat behind other environments. Here are the best options which have Haxe integration built in (code completion, syntax highlighting).
- Sublime Text 2
- Flash Develop (Windows only)
- Mono Develop
- EclipseHX
Developing in a plain text editor is another fine choice.
Scenes are the game's worlds. They consist of terrain (in the form of tiles), actors, backgrounds and some behaviors.
Actors are game objects. Every actor is associated with a Box2D body, a set of animations and some behaviors that bring it to life.
Behaviors are configurable, reusable components that add logic to Actors or Scenes.
(Talk about the order of execution)
These are the files that you're most likely to edit or view.
- Universal.hx - Entry point for a game. Sets up the screen / scaling options.
- com/stencyl/Engine.hx - Holds the "game loop" and is the center for pretty much everything.
- com/stencyl/Data.hx - Controls initial loading of data.
- com/stencyl/Input.hx - Controls all user input.
- com/stencyl/behavior/Script.hx - Holds the public API for all behaviors.
- com/stencyl/graphics/G.hx - The custom drawing API.
- com/stencyl/models/Actor.hx - The Actor class.
- com/stencyl/models/SoundChannel.hx - Controls Sound playback. Relevant for those tackling sound problems/deficiencies.
Data formats are relative to what the game engine sees. This may differ slightly from what Stencyl sees in a "source" project.
Stencyl stores its game data primarily in XML. These are the files you'll find.
- Assets/data/game.xml - Properties, controls, groups, game attributes, atlases and other game-wide data.
- Assets/data/behaviors.xml - General behavior properties.
- Assets/data/resources.xml - Properties for all game resources.
- Assets/data/scenes.xml - Scene listing.
- Assets/data/scene-[SCENEID].scn - Scene terrain data.
- Assets/data/scene-[SCENEID].txt - Scene terrain data (for HTML5).
- Assets/data/scene-[SCENEID].xml - All data for a scene except terrain.
For Stencyl 3.x and beyond, we'd like to break up the data into more individual files in order to make it more fault tolerant and shareable.