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 / InstanceExample.hx
Created September 4, 2021 16:47
An example of using instance properties in the Haxe programming language.
// A class; a template for creating objects with the properties listed in the class
class Duck {
public var age:Int;
public function new(age:Int) {
this.age = age;
}
}
class Test {
@KinoAR
KinoAR / InstanceStaticExample.hx
Created September 4, 2021 16:45
A gist displaying how to use the static vs instance properties.
//A class; a template for creating objects with the properties listed in the class
class Duck {
static public var CAN_FLY:Bool = true;
public var age:Int;
public function new(age:Int) {
this.age = age;
}
}
@KinoAR
KinoAR / StructInitExampleCode.hx
Created August 31, 2021 22:05
Advanced Example of the power of Struct Init
//Test it out here: https://try.haxe.org/#5Fb7F1f4
class Test {
public static function main() {
// Uncomment this and see what happens
// var firstUser:Person = {
// name: 'Tim'
// };
// trace(firstUser.name);
var user:Test2 = {
@KinoAR
KinoAR / StructInit.hx
Created August 31, 2021 21:44
An example of Struct Init usage within the Haxe programming language.
@:structInit class Person {
final name:String;
var age:Int = 30;
public function new(name:String, age:Int) {
this.name = name;
this.age = age;
}
public function greet()
/**
* 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 July 9, 2021 00:26
Advanced Enum Example
/**
* 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 June 6, 2021 15:36
Aseprite Build Macro example.
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 00:29
The fix for your collision detection problems in Flixel.
/*
* 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 01:10
An example extension for translation of a screen position into a world position for FlxObjects.
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 00:32
Example Function for getting the Screen Position. This is directly from the Flixel Code Base.
/**
* 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