Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Kino KinoAR

🏠
Working from home
View GitHub Profile
View ElementalMonster.hx
/**
* ADTs take in a parameter as you can see here.
*/
enum ElementalAtk {
FireAtk(?dmg:Int);
WaterAtk(?dmg:Int);
LightningAtk(?dmg:Int);
MagnetoAtk(?dmg:Int);
IceAtk(?dmg:Int);
@KinoAR
KinoAR / ElementalADTs.hx
Created Jul 9, 2021
Advanced Enum Example
View ElementalADTs.hx
/**
* ADTs take in a parameter as you can see here.
*/
enum ElementalAtk {
FireAtk(?dmg:Int);
WaterAtk(?dmg:Int);
LightningAtk(?dmg:Int);
MagnetoAtk(?dmg:Int);
IceAtk(?dmg:Int);
@KinoAR
KinoAR / AsepriteBuildMacro.hx
Created Jun 6, 2021
Aseprite Build Macro example.
View AsepriteBuildMacro.hx
package buildMacros;
import Structs.ZoomT;
import sys.FileSystem;
#if macro
import Structs.ChangeColorT;
import Structs.ChangeBrushT;
import haxe.macro.ExprTools;
import haxe.macro.Expr.Field;
import haxe.macro.Context;
@KinoAR
KinoAR / CollisionFix.hx
Created May 14, 2021
The fix for your collision detection problems in Flixel.
View CollisionFix.hx
/*
* From The Flixel Documentation
* The dimensions of the game world, used by the quad tree for collisions and overlap checks.
* Use .set() instead of creating a new object!
* ------
* By updating the value of this element, we can fix our collision detection once again.
* Best to call this in your update function.
*/
FlxG.worldBounds.set();
@KinoAR
KinoAR / SetScreenPosition.hx
Created May 2, 2021
An example extension for translation of a screen position into a world position for FlxObjects.
View SetScreenPosition.hx
import flixel.FlxCamera;
import flixel.FlxObject;
//Sets the screen position of a FlxObject using setPosition(which is in world coordinates)
function setScreenPosition(obj:FlxObject, point:FlxPoint, ?camera:FlxCamera) {
if (camera == null) {
camera = FlxG.camera;
}
if (obj.pixelPerfectPosition) {
@KinoAR
KinoAR / FlixelExample.hx
Created May 2, 2021
Example Function for getting the Screen Position. This is directly from the Flixel Code Base.
View FlixelExample.hx
/**
* Call this function to figure out the on-screen position of the object.
*
* @param Point Takes a `FlxPoint` object and assigns the post-scrolled X and Y values of this object to it.
* @param Camera Specify which game camera you want.
* If `null`, it will just grab the first global camera.
* @return The Point you passed in, or a new Point if you didn't pass one,
* containing the screen X and Y position of this object.
*/
public function getScreenPosition(?point:FlxPoint, ?Camera:FlxCamera):FlxPoint
@KinoAR
KinoAR / FlxSignalExample.hx
Last active May 1, 2021
An example of a FlxSignal in action.
View FlxSignalExample.hx
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 Apr 21, 2021
Haxe simple example of using enums.
View EnumDirection.hx
enum Direction {
Left;
Right;
Up;
Down;
}
function main() {
currentDirection(Left);
currentDirection(Right);
@KinoAR
KinoAR / PipeRest.hx
Last active Apr 21, 2021
Haxe Simple Pipe Example
View PipeRest.hx
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 Apr 21, 2021
Haxe Rest Summation Example
View SumRest.hx
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) {