On Friday, 14 April 2017 at 00:29:34 UTC, Jethro wrote:
Is there a way to retain the ordering of an associative array? When the elements are added then looped over using a foreach, the order is different.

Use a separate array to store the keys, order them all time when you add a new one, etc. This was the only workaround I could come up with for my engine (see it here: https://github.com/ZILtoid1991/pixelperfectengine/blob/master/source/PixelPerfectEngine/graphics/layers.d at Classes SpriteLayer and SpriteLayer32Bit), maybe in the future I'll come up with a better solution. I call this technique as "prioritized hash table" as the keys give them a certain priority, so there's no issue which sprite where supposed to show up.

Reply via email to