Skip to content

Instantly share code, notes, and snippets.

View KinoAR's full-sized avatar
🏠
Working from home

Kino KinoAR

🏠
Working from home
View GitHub Profile
@KinoAR
KinoAR / FlxSignalExample.hx
Last active April 19, 2022 09:38
An example of a FlxSignal in action.
import flixel.util.FlxSignal;
// for signals that don't need data, use FlxSignal
var signal = new FlxSignal();
// for signals that need data, use FlxTypedSignal with the correct function type
var stringSignal = new FlxTypedSignal<String->Void>();
function noParamCallback() {
trace('Dispatched void event');
}
@KinoAR
KinoAR / EnumDirection.hx
Created April 21, 2021 11:13
Haxe simple example of using enums.
enum Direction {
Left;
Right;
Up;
Down;
}
function main() {
currentDirection(Left);
currentDirection(Right);
@KinoAR
KinoAR / PipeRest.hx
Last active April 21, 2021 00:40
Haxe Simple Pipe Example
import haxe.Rest;
function main() {
var result = pipe('A',
(val:String) -> val.toUpperCase(),
(val2:String) -> val2 += " " + "World");
trace(result); //A World
}
@KinoAR
KinoAR / SumRest.hx
Created April 21, 2021 00:32
Haxe Rest Summation Example
import haxe.Rest;
function main() {
trace(sum(1, 2, 3));
trace(sum('Hello', ' World'));
}
function sum(...rest:Dynamic) {
var result = null;
for(element in rest) {
@KinoAR
KinoAR / ExternExample.hx
Created April 18, 2021 13:15
Example extern class taking from our own LunaTea development code.
package;
//Expose metatag is used to make sure that when the code is being referenced in the target language it'll be exposed
//for user's to override. I use this in JS to allow for modification, which is core to RPGMakerMV/MZ.
//Native metatag is used to make sure that when the code is compiled it uses the proper name.
//Native works both on classes and fields, which you can see for the x, y fields below.
@:expose("Point")
@:native("Point")
extern class Point extends pixi.core.math.Point {
/**
@KinoAR
KinoAR / PathingExample.hx
Created April 11, 2021 17:21
How To Setup Pathing For a FlxSprite
import flixel.util.FlxPath;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.util.FlxColor;
class Player extends FlxSprite {
public var walkPath:Array<FlxPoint>;
public function new(x:Float, y:Float) {
super(x, y);
@KinoAR
KinoAR / ObjectPoolingExample.hx
Last active April 29, 2021 01:55
How to do Object Pooling in Flixel
import flixel.FlxState;
import flixel.group.FlxGroup;
import flixel.FlxSprite;
import flixel.util.FlxColor;
class PlayState extends FlxState {
//bullet group for holding player bullets
public var playerBulletGrp:FlxTypedGroup<FlxSprite>;
public static inline var PLAYER_BULLET_CAP:Int = 20;
override public function create() {
@KinoAR
KinoAR / DepotMacros.hx
Last active June 23, 2021 13:39
Macro for Depot that turns your database elements/spreadsheet rows into a part of your code base.
package macros;
#if macro
import haxe.DynamicAccess;
import Types.DepotFile;
import sys.io.File;
import sys.FileSystem;
import haxe.macro.Expr.Field;
import haxe.Json;
import haxe.macro.Context;
@KinoAR
KinoAR / BuildMacroExample.hx
Created March 29, 2021 00:07
Build Macro Example in HaxeFlixel
package;
// Path to your own depot file
@:build(macros.DepotMacros.buildDepotFile('assets/data/database.dpo'))
class DepotData {}
@KinoAR
KinoAR / CollisionDetection.hx
Last active March 26, 2021 02:45
HaxeFlixel collision detection with groups example.
import flixel.FlxState;
import flixel.group.FlxGroup;
import flixel.FlxSprite;
import flixel.FlxG;
import flixel.util.FlxColor;
class PlayState extends FlxState {
//Creating the player, enemies, and npc group.
public var npcs:FlxTypedGroup<FlxSprite>;
public var enemies:FlxTypedGroup<FlxSprite>;