How to sort by a value that a FlxObject lacks?

33 views
Skip to first unread message

JustGabe

unread,
Dec 11, 2015, 7:46:21 PM12/11/15
to HaxeFlixel
I'm making an isometric game, so in order to make the movement and positionment smooth, I draw a square that represents the hero in a cartesian map (cartPlayer) at (100,100), so that the isometric char (class isoPlayer) is drawn at (0, 100), and also has a value which is 
cartX:Int = cartHero.x;
and is updated everytime I move the cartesian hero (making the isometric hero to move accordingly).  The same way, other NPC's (class NPC) and Enemies (class Enemy) are drawn with that extra value.

What I want to do, is to sort the group with THAT "cartX" value, but the function recieves a FlxObject which doesn't have a cartX value, and I'm lost at how to manage the sorting using that value, specially when I have 3 different class types (isoPlayer, isoNPC and isoEnemy) and plan to make an isoOverlayTile for trees, bushes and stuff.

JustGabe

unread,
Dec 12, 2015, 11:17:12 AM12/12/15
to HaxeFlixel
So, a possible solution could be to make every player, npc and enemy an extension of an IsoSprite which will hold the public var "cartX", and then edit the FlxSort.hx like this:
public static inline function byCartesianPosition(Order:Int, Obj1:IsoSprite, Obj2:IsoSprite):Int
{
return byValues(Order, Obj1.cartX, Obj2.cartX);
}

But it throws me these errors:
source/Testing06.hx:244: characters 22-49 : Order : Int -> Obj1 : IsoSprite -> Obj2 : IsoSprite -> Int should be Int -> flixel.FlxSprite -> flixel.FlxSprite -> Int
source/Testing06.hx:244: characters 22-49 : Cannot unify argument 2
source/Testing06.hx:244: characters 22-49 : flixel.FlxSprite should be IsoSprite
source/Testing06.hx:244: characters 22-49 : For function argument 'Function'

Jeru Sanders

unread,
Dec 13, 2015, 6:36:59 PM12/13/15
to HaxeFlixel
The function must take FlxSprites, you can cast the, once inside.

JustGabe

unread,
Dec 14, 2015, 4:47:43 PM12/14/15
to HaxeFlixel
I already got it, thank you. All that I needed was to declare a public var in the FlxObject and then define the value after creating the sprites. It kind of worked thou, since sometimes the sprites still overlap when they shouldn't, but it's still a leap.
Reply all
Reply to author
Forward
0 new messages