Skip to content

Instantly share code, notes, and snippets.

View AxGord's full-sized avatar
🦄
Pony

Alexander Gordeyko AxGord

🦄
Pony
View GitHub Profile
class Test {
static function main() {
var a = new Priority();
a.add(3, 2);
a.add(1, 1);
trace(a.a);
}
}
var w = Config.width;
var h = Config.height;
var space:NapeSpaceView = new NapeSpaceView(new Point<Float>(0, 600));
space.debugLines = {size: 3, color: 0xFFFFFF};
c.addChild(space);
space.createStaticRect(new Rect<Float>(50, h - 50, w - 100, 1));
space.createStaticRect(new Rect<Float>(w - 50, 50, 1, h - 100));
@AxGord
AxGord / GenericBuildMacro.hx
Created June 9, 2018 15:35
Generic macro abstract function!
import haxe.macro.TypeTools;
import haxe.macro.Expr;
import haxe.macro.Context;
import haxe.macro.Type;
class GenericBuildMacro {
static public function build():ComplexType {
@AxGord
AxGord / ParentClass.hx
Created February 24, 2016 11:10
Asset managet example
/**
* ParentClass
* @author AxGord <axgord@gmail.com>
*/
@:assets_path('assets')
class ParentClass implements HasAsset {
@:asset public static var MY_ASSET = 'myasset3.png';
static function main() {
import pony.time.Tween;
class TweenExample {
static function main() {
var obj = new Sprite();
new Tween(20...100, '3s').onUpdate << function(v:Float) obj.y = v;
}
}
class LinkDemo implements pony.magic.HasLink {
static var index:Int = 5;
static var visualIndex(link, never):String = Std.string(index + 1);
static function main() {
trace(visualIndex);//=>6
index = 10;
trace(visualIndex);//=>11
}
@AxGord
AxGord / Container.hx
Last active January 19, 2016 17:19
Pony + pixijs
import pixi.core.graphics.Graphics;
import pixi.core.sprites.Sprite;
import pixi.core.textures.Texture;
import pony.time.DeltaTime;
class Container extends Sprite {
private var _bunny:Sprite;
public function new(width:Float, height:Float) {
@AxGord
AxGord / Streams.hx
Last active September 26, 2015 01:16
Using pony signals for streams
static function streamToString() {
var streamInput = new Event1<Int>();
var streamOutput:Signal1<Int> = streamInput;
var subStream = streamOutput.convert1(
function(e:Event1<String>, v:Int) e.dispatch(v == 2 ? 'two' : Std.string(v))
);
subStream.add(function(s:String) trace(s));
macro public function add(th:Expr, f:Expr, ?priority:ExprOf<Int>):Expr {
if (priority == null) priority = macro 0;
return switch Context.typeExpr(f).t {
case TFun(args, ret):
switch ret {
case TAbstract(t, p):
var n = t.get().name;
if (n != 'Bool' && n != 'Void')
Context.fatalError('Wrong return type', Context.currentPos());
@AxGord
AxGord / SignalTest.hx
Last active September 17, 2015 16:22
package;
import pony.events.Signal;
/**
* ...
* @author AxGord <axgord@gmail.com>
*/
class SignalTest {
static function main() {