The Daily Click ::. Forums ::. Klik Coding Help ::. Best way to Order sprites?
 

Post Reply  Post Oekaki 
 

Posted By Message

phanto



Registered
  21/09/2005
Points
  70
20th July, 2011 at 14:23:13 -

Sorry if the title is confusing, I'll try to explain. I have a game with 63x32 isometric grid in which the player moves around units (sprites).
The sprites (Active Objects) have a Y value/Y-position, and what I want is to make a unit with a higher Y value (i.e. closer to the bottom of the screen) to be Ordered/put on top of a sprite with lesser Y value.
In other words, I don't want a sprite to have his head covered by the feet of the sprite behind him. I don't want units with Y position lower than tree-sprites to be shown in front of the trees either.

I've tried for two days to make this work. I've tried using Y-position, Alternate Values based on Y-position, and extensions that either crash MMF or don't work.

I have a legal MMF2 Dev version so if any of you guys know of any extensions that might be used to sort this out I'd be grateful too.

 
n/a

phanto



Registered
  21/09/2005
Points
  70
20th July, 2011 at 14:29:32 -

Hmm I found this
http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=23664
"- An efficient layer sorting process for objects moving under, over and behind other objects."
Sounds about right...
I'll check it out. But I'm not using arrays so it might not help.

EDIT: Didn't really help.

My problem is related to get multiple units of the same Active Object (e.g. "Player") to be Ordered differently, and to each other. But I can't really say "Put Player in front of Player if Y(Player)>Y(Player).

I need something that says "Take everything on Y-value xxx and put them infront of everything at lesser Yvalues".

Edited by phanto

 
n/a

Jenswa

Possibly Insane

Registered
  26/08/2002
Points
  2723
20th July, 2011 at 16:04:44 -

Hi phanto,

why can't you use:


Originally Posted by phanto
"Put Player in front of Player if Y(Player)>Y(Player).



Because I think that's the way you should do it.

Since you know all the y coordinates of the objects you should use these together with an alternate value.

The one with the lowest y value should be on top of all, right? So the one with the highest y value should be on the back, try sorting the objects from the one that's at the back to the front. Use an alternative value to store a 0 for the object at the back and store the last number in the one belonging to the front on top of every other object.

Once sorted, you can loop through the list and bring each object to the front. The first object from the list (lowest alternate value: 0) should be at the back and when reaching the last object from the list (highest alternate value) should be on front, because it's brought the the front as last and is on top of every other object.

The only difficult thing is sorting the list but perhaps MMF2 has some kind of built in feature for this and with sorting I mean putting the right value in the alternate value.

A little example with three objects, they should be numbered 0, 1 and 2 in the alternate value.
0 will be brought to front, then 1 will be brought to front and is in front of 0, last 2 will be brought to front and is in front of 0 and 1.

So after sorting, bring to front will do your job. This is basically sorting sprites by z-order (where the z-order depends on the y-axis, search the internet for more information).

PS: At first when I read the topic of this post, I thought you wanted to order sprite from someone.

 
Image jenswa.neocities.org

markno2



Registered
  06/06/2006
Points
  865

Game of the Week WinnerVIP MemberPicture Me This Round 30 Winner!Weekly Picture Me This Round 39 Winner!Kliktober Special Award Tag
20th July, 2011 at 16:48:08 -

Use the layer object.

 
Discarded pizza boxes are an indispensable source of cheese.

phanto



Registered
  21/09/2005
Points
  70
20th July, 2011 at 17:49:16 -

Jenswa- Thx but I'm using like 20 alternate values on every object already... It's a pretty heavy strategic/rpg'ish game, and for some reason i thought sorting Order would be good to do last -_-

marky_2 - Thx I'll try that.

 
n/a

phanto



Registered
  21/09/2005
Points
  70
20th July, 2011 at 19:00:42 -

Wow. I thought using Y-sorting with the Layer object on an Always-line would lag the game to hell... but it works with no problems! No need for backgrounds either. Great extension. Thanks for the tip!

 
n/a
   

Post Reply



 



Advertisement

Worth A Click