Created
April 20, 2018 22:50
-
-
Save 01010111/668e8cbd937eb137a84eaf8725c54951 to your computer and use it in GitHub Desktop.
3D FLIXEL WOO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import flixel.FlxG; | |
import flixel.FlxSprite; | |
import flixel.group.FlxGroup.FlxTypedGroup; | |
import flixel.math.FlxPoint; | |
using zero.ext.FloatExt; | |
class ThreeDeeObject extends FlxTypedGroup<Slice> | |
{ | |
public var base:FlxSprite; | |
public var offset:Float = 1; | |
public function new(p:FlxPoint) | |
{ | |
super(); | |
for (i in 0...8) add_sprite(i, p); | |
} | |
function add_sprite(i:Int, p:FlxPoint) | |
{ | |
var s = new Slice(p.x, p.y, i - 1, this); | |
s.loadGraphic('assets/images/box.png', true, 24, 24); | |
s.animation.frameIndex = i; | |
if (i == 0) s.alpha = 0.25; | |
if (i == 1) base = s; | |
add(s); | |
} | |
function get_y():Float return base.getMidpoint().y; | |
} | |
class Slice extends FlxSprite | |
{ | |
var z:Int; | |
var parent:ThreeDeeObject; | |
public function new(x:Float, y:Float, z:Int, parent:ThreeDeeObject) | |
{ | |
super(x, y); | |
this.z = z; | |
this.parent = parent; | |
} | |
override public function update(e:Float) | |
{ | |
super.update(e); | |
if (this == parent.base) return; | |
var offset = ((FlxG.camera.angle + 90) * -1).vector_from_angle(z * parent.offset).to_flx(); | |
setPosition(parent.base.x + offset.x, parent.base.y + offset.y); | |
angle = parent.base.angle; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment