Skip to content

Instantly share code, notes, and snippets.

// parseTileLevel at the beginning
// genPath kinda often
// orient frequently
function parseTileLevel() {
// put this in a more central place?
// parse tile level into graph
graph = new Graph();
final lvl = CharVars.get().tileLevel;
@MSGhero
MSGhero / TextUnits.txt
Created September 24, 2020 01:25
Unit tests for OpenFL TextField's replaceText() and setTextFormat()
text = new TextField();
text.text = "EXAMPLE";
text.selectable = true;
text.wordWrap = false;
text.type = "input";
text.border = true;
text.width = 300;
text.borderColor = 0x000000;
// cases where beginIndex != endIndex
@MSGhero
MSGhero / SmartWordWrap.hx
Last active April 1, 2020 07:29
Layout-aware type text that word wraps without bumping words down
// just contains excerpts and comments
// does not work on Flash. Fine on Windows and HTML5 at least
// involves diving into OpenFL's private API, so no guarantees this will work forever. But it works now!
// probably errors if you start fiddling with the textfield, like setting formats or appendText()
// SmartWordWrap.hx
class SmartWordWrap extends openfl.text.TextField { // gotta extend TextField to have access to internals
var layoutGroups:openfl.Vector<openfl._internal.text.TextLayoutGroup> = new Vector(); // this will cache character information
@MSGhero
MSGhero / flixel-big-issues.md
Last active October 24, 2020 06:14
A list of issues in Flixel everyone keeps complaining about, so that we actually propose fixes

FlxSpriteGroup

  • FlxSpriteGroup shouldn't exist, but Flixel's "easy to get into" mindset means it has to exist. So now, the class is halfway between AS3 (sprite grouping is the default) and Kha (sprite grouping is DIY)
  • Issues: setting alpha to 0 is unrecoverable. MouseChildren handling subpar, especially compared to flash.display.Sprite#mouseChildren
  • Potential solution: give FlxBasic/Object/Sprites a parent:FlxTypedGroup<> property and propagate that change throughout the lib
  • Impact to lib: major
  • Effort required: possibly a lot
  • Breaking: mouseChildren behavior could be changed to match AS3's

Inheritance

  • Flixel greatly relies on inheritance, which makes it difficult to use
@MSGhero
MSGhero / InputExcerpt.hx
Last active October 8, 2017 15:23
Excerpt of InputUtil
public static var defaultPadMappings:Array<Array<FlxGamepadInputID>> = [
[FlxGamepadInputID.LEFT_STICK_DIGITAL_LEFT, FlxGamepadInputID.DPAD_LEFT],
[FlxGamepadInputID.LEFT_STICK_DIGITAL_RIGHT, FlxGamepadInputID.DPAD_RIGHT],
[FlxGamepadInputID.LEFT_STICK_DIGITAL_UP, FlxGamepadInputID.DPAD_UP],
[FlxGamepadInputID.LEFT_STICK_DIGITAL_DOWN, FlxGamepadInputID.DPAD_DOWN],
[FlxGamepadInputID.RIGHT_STICK_DIGITAL_LEFT],
[FlxGamepadInputID.RIGHT_STICK_DIGITAL_RIGHT],
[FlxGamepadInputID.RIGHT_STICK_DIGITAL_UP],
[FlxGamepadInputID.RIGHT_STICK_DIGITAL_DOWN],
[FlxGamepadInputID.A],
@MSGhero
MSGhero / PlayState.hx
Last active September 3, 2016 05:04
9-Slice Algo Test
package;
import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
import flixel.FlxSprite;
import flixel.FlxState;
/**
@MSGhero
MSGhero / Direction.hx
Last active September 25, 2015 09:03
Compass direction <=> degree measure abstract for Haxe. Useful for me, maybe for you.
package entities;
import nape.geom.Vec2;
/**
* @author MSGHero
*/
@:enum
abstract Direction(Int) {