Friday, December 19, 2014

Using OpenFL Templates to Modify Functionality in Haxe Libraries

I recently had to modify some functionality in the FlxAnimationController class in HaxeFlixel 3.3.6 for our game Spacejacked.

Since the change was rather minor, and I didn't want to clone the FlxAnimationController and FlxSprite (which uses FlxAnimationController) classes, I decided to use the templating capabilities of the OpenFL project XML format.

FlxAnimationController is located under the flixel/animation directory of the Flixel project source folder. To replace the functionality, I copied FlxAnimationController.hx to templates/haxe/flixel/animation/FlxAnimationController.hx in my own project folder and made my own changes there.

To get OpenFL to use this file instead of Flixel's, I simply added this template tag to my application.xml:
<template path="templates" />