+
Cheat Sheet
+
+
+
package;
+
+import flixel.FlxSprite;
+import flixel.FlxG;
+
+class MySprite extends FlxSprite
+{
+ public function new()
+ {
+ super();
+ }
+
+ override public function update(elapsed:Float):Void
+ {
+ super.update(elapsed);
+ }
+}
+
HAXE
+
+
package;
+
+import flixel.FlxState;
+import flixel.FlxG;
+
+class MyState extends FlxState
+{
+ override public function create():Void
+ {
+ super.create();
+ }
+
+ override public function update(elapsed:Float):Void
+ {
+ super.update(elapsed);
+ }
+}
+
HAXE
+
+
FlxG.switchState(new MyState());
+
HAXE
+
+
loadGraphic("assets/my_sprite.png");
+
+
+makeGraphic(100, 100, 0xFFFFFFFF);
+
+
+updateHitbox();
+
HAXE
+
+
+- setFormat(font, size, color, alignment)
+- setBorderStyle(style, color, size)
+
+
import flixel.text.FlxText;
+import flixel.util.FlxColor;
+
HAXE
+
myText = new FlxText(0, 0, 500);
+myText.text = "Hello World";
+myText.setFormat("assets/font.ttf", 20, FlxColor.WHITE, CENTER);
+myText.setBorderStyle(OUTLINE, FlxColor.RED, 1);
+
HAXE
+
+
import flixel.ui.FlxButton;
+
HAXE
+
myButton = new FlxButton(0, 0, "Label", myCallback);
+
+
+myButton.loadGraphic("assets/custom.png", true, width, height);
+
HAXE
+
function myCallback():Void
+{
+}
+
HAXE
+
+- myButton.label is a
FlxText
, use setFormat()
and setBorderStyle()
to customise.
+
+
+
With the stock Project.xml
, simply place them in your project's assets/music
and assets/sounds
subfolders and they're ready to use.
+
Sound effects are usually in WAV format (44.1 kHz source).
+
Music must be in MP3 format (44.1 kHz source) for Flash, and OGG for everything else. To support both Flash and non-Flash platforms without bundling both formats in your output, you can replace the stock <assets>
tag in your Project.xml
with this:
+
<assets path="assets" exclude="*.ogg" if="flash"/>
+<assets path="assets" exclude="*.mp3" unless="flash"/>
+
XML
+
Play in your code:
+
+FlxG.sound.play(AssetPaths.mySound__wav);
+
+FlxG.sound.play("assets/sounds/mySound.wav");
+
+
+FlxG.sound.playMusic(AssetPaths.myMusic__mp3);
+
+FlxG.sound.playMusic(AssetPaths.myMusic__ogg);
+
+FlxG.sound.playMusic(FlxAssets.getSound("assets/music/myMusic"));
+
HAXE
+
+
+if (FlxG.keys.justPressed.A) {}
+if (FlxG.keys.pressed.A) {}
+if (FlxG.keys.justReleased.A) {}
+
+
+if (FlxG.keys.anyPressed([RIGHT, D])) {}
+
HAXE
+
+
ANY
+
A
...Z
+
UP
DOWN
LEFT
RIGHT
+
SPACE
ENTER
ESCAPE
+
ZERO
ONE
TWO
THREE
...NINE
+
F1
...F12
+
ALT
+BACKSLASH
+BACKSPACE
+CAPSLOCK
+CONTROL
+DELETE
+HOME
+INSERT
+QUOTE
+PERIOD
+PLUS
+MINUS
+PAGEUP
+PAGEDOWN
+RBRACKET
+GRAVEACCENT
+TAB
+SLASH
+SEMICOLON
+
NUMPADZERO
NUMPADONE
NUMPADTWO
...NUMPADNINE
+
+
if (FlxG.mouse.pressed) {}
+if (FlxG.mouse.justPressed) {}
+if (FlxG.mouse.justReleased) {}
+
HAXE
+
+
+FlxG.mouse.x;
+FlxG.mouse.y;
+
+
+FlxG.mouse.screenX;
+FlxG.mouse.screenY;
+
HAXE
+
+
Current "delta" value of mouse wheel. If the wheel was just scrolled up, it will have a positive value. If it was just scrolled down, it will have a negative value. If it wasn't just scroll this frame, it will be 0.
+
FlxG.mouse.wheel;
+
HAXE
+
+
var clickableSprite:FlxSprite;
+
+
+
+
+FlxMouseEventManager.init();
+
+
+
+
+var pixelPerfect = false;
+FlxMouseEventManager.add(clickableSprite, mousePressedCallback, mouseReleasedCallback, null, null, false, true, pixelPerfect, [FlxMouseButtonID.LEFT, FlxMouseButtonID.RIGHT]);
+
+
+
+function mousePressedCallback(sprite:FlxSprite)
+{
+ if (FlxG.mouse.justPressed)
+ {
+
+ }
+ else if (FlxG.mouse.justPressedRight)
+ {
+
+ }
+}
+
+function mouseReleasedCallback(sprite:FlxSprite)
+{
+}
+
HAXE
+
+
for (touch in FlxG.touches.list)
+{
+ if (touch.justPressed) {}
+ if (touch.pressed) {}
+ if (touch.justReleased) {}
+}
+
HAXE
+
+
+touch.x;
+touch.y;
+
+
+touch.screenX;
+touch.screenY;
+
HAXE
+
+
+
"Swipes" from both mouse and touch input that have just been released:
+
for (swipe in FlxG.swipes)
+{
+
+
+
+
+
+
+
+
+}
+
HAXE
+
+
import flixel.util.FlxSignal;
+
HAXE
+
+var signal = new FlxSignal();
+
+var stringSignal = new FlxTypedSignal<String->Void>();
+
HAXE
+
Note: FlxSignal
is nothing but a convenient shortcut for FlxTypedSignal<Void->Void>
+
signal.add(voidCallback);
+stringSignal.add(stringCallback);
+
HAXE
+
function voidCallback()
+{
+ trace("Hello");
+}
+
+function stringCallback(text:String)
+{
+ trace(text);
+}
+
HAXE
+
+signal.dispatch();
+stringSignal.dispatch("World");
+
HAXE
+
You can have up to 4 parameters in your signal:
+
var collisionNotify = new FlxTypedSignal<FlxObject->FlxObject->Bool->Bool->Void>();
+collisionNotify.add(collisionCallback);
+
+function collisionCallback(source:FlxObject, target:FlxObject, shouldKillSource:Bool, shouldKillTarget:Bool):Void (...)
+
HAXE
+
+
import flixel.util.FlxTimer;
+
HAXE
+
+new FlxTimer().start(10.0, myCallback, 3);
+
HAXE
+
function myCallback(timer:FlxTimer):Void
+{
+}
+
HAXE
+
+- Setting
loops
to 0
results in an endless loop.
+reset(?NewTime)
restarts the timer, optionally with a new duration.
+cancel()
stops the timer and removes it from the timer manager.
+
+
+
+FlxG.random.int(0, 10);
+
+
+FlxG.random.float(0.0, 10.0);
+
+
+FlxG.random.bool(50);
+FlxG.random.bool(10);
+
HAXE
+
+
Check the demo to visualize all FlxTween
types.
+
+- tween(Object, Values, Duration, ?Options)
+
+
import flixel.tweens.FlxTween;
+import flixel.tweens.FlxEase;
+
HAXE
+
+FlxTween.tween(sprite, {x: 100, y: 200}, 3.0, {ease: FlxEase.quadInOut, complete: myCallback});
+
HAXE
+
function myCallback(tween:FlxTween):Void
+{
+}
+
HAXE
+
+
+
{ease: FlxEase.quadInOut}
+
HAXE
+
+
{complete: callbackFunction}
+
HAXE
+
function callbackFunction(tween:FlxTween):Void
+{
+}
+
HAXE
+
+
{type: FlxTweenType.PINGPONG}
+
HAXE
+
+- FlxTweenType.BACKWARD: plays tween in reverse direction
+- FlxTweenType.LOOPING: restarts immediately when it finishes.
+- FlxTweenType.ONESHOT: stops and remove itself from its core container when it finishes.
+- FlxTweenType.PERSIST: stops when it finishes.
+- FlxTweenType.PINGPONG: plays tween hither and thither
+
+
+
{loopDelay: 1.0}
+
HAXE
+
+
{startDelay: 2.0}
+
HAXE
+
+
Check the demo to visualize all FlxEase
types.
+
+-
+
backIn
, backInOut
, backOut
+
+-
+
bounceIn
, bounceInOut
, bounceOut
+
+-
+
circIn
, circInOut
, circOut
+
+-
+
cubeIn
, cubeInOut
, cubeOut
+
+-
+
elasticIn
, elasticInOut
, elasticOut
+
+-
+
expoIn
, expoInOut
, expoOut
+
+-
+
quadIn
, quadInOut
, quadOut
+
+-
+
quartIn
, quartInOut
, quartOut
+
+-
+
quintIn
, quintInOut
, quintOut
+
+-
+
sineIn
, sineInOut
, sineOut
+
+
+
+
FlxGroup
is a shortcut for FlxTypedGroup<FlxBasic>
. Use FlxTypedGroup<MyOwnClass>
if you need to access your own variables and functions when iterating over the container.
+
+
for (member in myGroup)
+{
+ member.x += 10;
+ member.mySpecificFunction();
+}
+
HAXE
+
+
FlxG.overlap(objectOrGroup1, objectOrGroup2, myCallback);
+
HAXE
+
function myCallback(object1:FlxObject, object2:FlxObject):Void
+{
+}
+
HAXE
+
Or use FlxG.collide()
which calls FlxG.overlap()
and presets the processCallback
parameter to FlxObject.separate()
.
+
+
+FlxG.worldBounds.set(tilemap.x, tilemap.y, tilemap.width, tilemap.height);
+
HAXE
+
+
+FlxG.collide(player, level);
+
+if (player.isTouching(DOWN))
+{
+
+}
+
+
+super.update(elapsed);
+
HAXE
+
+
+setPosition(10, 100);
+
+last.set(x, y);
+
HAXE
+
+
var overlapping = FlxG.pixelPerfectOverlap(sprite1, sprite2);
+
HAXE
+
+
Dynamically draw: circle, ellipse, line, polygon, triangle, rect, round rect and rect complex.
+
using flixel.util.FlxSpriteUtil;
+
HAXE
+
Haxe docs about the using
keyword: haxe.org/manual/lf-static-extension.html.
+
var canvas = new FlxSprite();
+canvas.makeGraphic(FlxG.width, FlxG.height, FlxColor.TRANSPARENT, true);
+add(canvas);
+
HAXE
+
The last argument of makeGraphic()
is Unique
, whether the graphic should be an unique instance in the graphics cache, if you create multiple graphics like this, set it to true
to avoid conflicts.
+
var lineStyle:LineStyle = {color: FlxColor.RED, thickness: 1};
+var drawStyle:DrawStyle = {smoothing: true};
+
HAXE
+
+canvas.drawCircle(x, y, radius, color, lineStyle, drawStyle);
+
+
+canvas.drawEllipse(x, y, width, height, color, lineStyle, drawStyle);
+
+
+canvas.drawLine(startX, startY, endX, endY, lineStyle);
+
+
+var vertices = new Array<FlxPoint>();
+vertices[0] = new FlxPoint(0, 0);
+vertices[1] = new FlxPoint(100, 0);
+vertices[2] = new FlxPoint(100, 300);
+vertices[3] = new FlxPoint(0, 100);
+canvas.drawPolygon(vertices, color, lineStyle, drawStyle);
+
+
+canvas.drawTriangle(x, y, height, color, lineStyle, drawStyle);
+
+
+canvas.drawRect(x, y, width, height, color, lineStyle, drawStyle);
+
+
+canvas.drawRoundRect(x, y, width, height, ellipseWidth, ellipseHeight, color, lineStyle, drawStyle);
+
+
+canvas.drawRoundRectComplex(x, y, width, height, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius, color, lineStyle, drawStyle);
+
HAXE
+
Use canvas.fill(FlxColor.TRANSPARENT);
to clear the canvas.
+
+
+scrollFactor.set(0, 0);
+
HAXE
+
+
+uiCamera = new FlxCamera(0, 0, screenWidth, screenHeight);
+uiCamera.bgColor = FlxColor.TRANSPARENT;
+
+
+FlxG.cameras.add(uiCamera, false);
+
+
+hudElement.cameras = [uiCamera];
+
+FlxG.camera.bgColor = 0xff626a71;
+FlxG.camera.zoom = 0.5;
+
HAXE
+
+
Press ~ key
to open it during runtime, or open by code with FlxG.debugger.visible = true
.
+
+FlxG.log.add("My var: " + myVar);
+
+FlxG.log.redirectTraces = true;
+trace("My var: ", myVar);
+
+
+FlxG.watch.add(object, "property");
+
+
+FlxG.watch.addMouse();
+
+
+FlxG.debugger.addTrackerProfile(new TrackerProfile(Player, ["x", "y", "jumping", "ladder"], []));
+FlxG.debugger.track(player, "Hero");
+
HAXE
+
+
FlxG.mouse.visible = false;
+
HAXE
+
+
acceleration.y = 600;
+
HAXE
+
+
+group.sort(FlxSort.byY, FlxSort.ASCENDING);
+
+
+var group = new FlxTypedGroup<ZSprite>();
+group.sort(
+ function(order:Int, sprite1:ZSprite, sprite2:ZSprite):Int
+ {
+ return FlxSort.byValues(order, sprite1.z, sprite2.z);
+ },
+ FlxSort.ASCENDING
+);
+
HAXE
+
+
+var tileSize = FlxPoint.get(16, 16);
+
+var actionTileset = FlxTileFrames.fromGraphic(FlxG.bitmap.add("assets/images/ui/actions.png"), tileSize);
+
+
+tileSize.put();
+
HAXE
+
+
+
+
+
+
+