Is there any way to draw Sprite between two tiles of Tilesheet??

70 views
Skip to first unread message

dullman

unread,
Nov 29, 2015, 1:00:32 PM11/29/15
to HaxeFlixel
Hi although many of my question here remains unanswered and for that i need to create my own logic from scratch, but i want to ask if there is a method to display sprite between two tiles my example that i had in background group two trees with one tile empty between them, what i want is that the character when stand on empty tile will be drawn on one tree and behind second (i mention that character is bigger than one tile), currently i use three groups background, character, foreground but in a case when character should be drawn on a top of tree it's drawn behind since foreground is later added than character group. I thought about creating layer order but for that i should break sprites into tiles and to be truthful i would love as small interference as possible since i believe current code is optimized.

Tembac

unread,
Nov 30, 2015, 8:27:09 PM11/30/15
to HaxeFlixel
You can use the sort functions. You need to put all the items in one group and make a sort by Y.

http://api.haxeflixel.com/flixel/util/FlxSort.html?

dullman

unread,
Nov 30, 2015, 10:44:25 PM11/30/15
to HaxeFlixel
From my understanding it's won't work since tilemap count as single object which in my opinion is stupid since it doesn't allow to place sprite on the same level as tilemap, and i knew this function but as i stated it works only if we would have collection of sprites not tilemap, i ask is there a way to inject sprite between two tilemap objects? or the only way is write render and tilemap class by myself which seems to be norm for haxeflixel, since it's lack any helpful code besides required by simplest games.

Jeru Sanders

unread,
Dec 1, 2015, 4:36:22 PM12/1/15
to haxef...@googlegroups.com
Tilemaps are by definition single objects, the individual objects sacrifice their identities and are blitted together for rendering speed, collision boxes are generated for convenience. If you want them to be individuales you can pop them all out with:

for (i in 0...tilemap.totalTiles) add(tilemap.tileToFlxSprite(Std.int(i/tilemap.widthInTiles), i%widthInTiles, -1))

And watch your frame rate plummet with the thousands of added draw and update calls.

To solve the problem there's a few methods, the most obvious way to fix this is to remove the trees from your tilemap and render them as separate FlxSprites and swap them in your foreground/background groups.

But that can be slow if you have a very large number of objects that need to be depth sorted. Another way is to have a foreground and background tilemaps and set the tiles depending on the depth, the problem with this is if there's multiple objects that need to be between trees.

Yet a third way is to use tileToFlxSprite to generate a tree sprite and place it on top when needed. This is probably the most optimal but requires a lot of logic to be written.

dullman

unread,
Dec 3, 2015, 7:49:18 AM12/3/15
to HaxeFlixel
As for tileToFlxSprite i saw this but i was afraid that it slow down rendering (which you confirm in your post), a mean HaxeFlixel should just have some FlxTile which is optimized, than use generic FlxSprite. Also having tilemaps as single objects is somewhat stupid from gaming approach since it's doesn't allow any depth sorting so it aren't useful in creating more complicated games.
Your second proposition is simple and i use at beginning but it doesn't resolve since object on middle layer always drawn besides foreground, so even if logic says that character is down from tree it still drawn behind.
Your first proposition seems at best something that is use tilemap for background and else are objects, which will be pain from creating maps, besides if we use that approach why just don't create a painted background and add to this object?? It lose all advantages of creating game map from tiles, and it didn't give any pros if we don't have artist who will create background and objects.

As your third proposition i'm not quite understand what you mean, but from what i understand you propose that every sprite (or character in this case) should cause to tiles behind them to be changed to FlxSprite and then sort them by depth, which might be good idea to just show on right position, but if i plan add also shadows and lights to map i need to think about it to be actual doable.

Myself i thought about manipulating directly bitmapData, but since must say i don't know how it is optimized in haxe i'm afraid that is also something which will slow down game (To be truthful i need a pixel manipulation since i need to tint bitmap with map of tint which depends on lights, shadows, and time, so just copy tile to tile with copy pixels doesn't resolve my problem).

Jeru Sanders

unread,
Dec 3, 2015, 3:11:29 PM12/3/15
to HaxeFlixel
FlxSprite extends FlxObject extends FlxBasic.
If you move from FlxSprite to FlxObject you lose almost all graphical functionality, if there was a way to make FlxSprite's arbitrarily faster without a huge loss of features we'd probably just all use those.

In my first case, and I think the most reasonable case, just loop through the map when it's loaded, record the locations of all the trees, then create tree objects at those locations. You don't need to modify the map to do this.

But as I said, there may be too many trees, in that case do this at runtime and only for trees very near the player.

dullman

unread,
Dec 4, 2015, 1:22:33 AM12/4/15
to HaxeFlixel
Hmm i see, if you describe your idea like that it seems reasonable, but the tree object i gave as example is only one of object that i want to be sorted by y, basically all objects which height (or in game terms z axis) are > 0 i want to be sorted so if i plan to have a standard map with 100x100 tile than if we count those objects we will probably get amount at 500-1000 (I consider that a tree is build for example from nine tile, beacuse from programming side i cant say if tile is the part of larger object or single object), so on map i would have additional ~1000 sprites to loop through, if i use your proposed approach it would go down to ~50 objects which is more acceptable value, although it's need to rewrite render function (but it's not very complicated since it's few modification with DrawStackItem object to keep information if it's a tile or normal sprite)
Reply all
Reply to author
Forward
0 new messages