makotok/Hanappe

Request: z-ordering of objects

Closed this issue · 12 comments

Being able to set or change the z-order of objects in Flower would be particularly useful.

Hello.
Thank you for feedback.

We can change the Z position in the "MOAIProp:setLoc".
In addition, we can change the drawing order in the "MOAILayer:setSortMode".

Is it necessary to method other than this?

It might be my lack of understanding, but none of these methods seems to work satisfactorily.

If I understand this correctly, "MOAILayer:setSortMode" will set the drawing order for the entire layer, which in this case isn't especially useful since the z-order should reflect how things are drawn in Tiled. And I was thinking more of changing the drawing order for single objects during game play. "MoAIProp:setLoc" however, seems to be the right way to do it, but I can't get this to work the way I believe it's intended. If I use this to change the z value of an object from 0 to let's say 1, nothing really happens. The objects are still rendered in the same z-order as before. And if I change the z value to anything other than -1, 0 or 1, the object just disappears.

To illustrate what I'm after, an example would be a planet with a revolving satellite. The planet is given a z-value of 1, the satellite, when in front of the planet, would be given a z-value of 2 and when it returns to pass behind the planet, the satellite's z-value is then set to 0. A spaceship flying in front of the planet (and satellite) would need a z-value of at least 3.

Please have me excused if this already is possible, but I just can't make it work.

Quedex, I did it using setPriority.

@hugohomesquita
Thanks for your input, but I can't seem to get "setPriority" to work either. Have you successfully got this to work on single objects on a Tiled map with Flower? Have you managed to change the z-order/priority during code execution?

MOAILayer can be drawn in any order.
The default is to draw in the order in which they were added.

If you set the sortMode, to draw sorted by certain logic.
For example, to draw sorted by priority in the following cases.

  • MOAILayer.SORT_PRIORITY_ASCENDING

When drawing the Z position, using the following constants.

  • MOAILayer.SORT_Z_ASCENDING

By calling the updateRenderOrder, tile map of Flower sets in order the priority.
If you set the sortMode of Layer, in accordance with the order.

However, when you generate a renderer layer, priority is not set.
Therefore, if you draw a new tile, necessary to call updateRenderOrder occurs.

This behavior improves.

look at this: http://www.youtube.com/watch?v=70IKi6rE8pw is that what you want?

When I call "updateRenderOrder" every single object's priority is reset to 20001?!?!

@hugohomesquita
That's it. Nice work!

And to both of you, thanks for info and support.

Was changed when generating Renderer, to set the Priority.
necessary to call updateRenderOrder should be reduced.

In addition, updateRenderOrder updates by taking the margin.
Therefore, it is possible to change the drawing order freely within the margin.

I think I get that part now. But I still don't understand how to change the rendering order of an object.
Let's say I have an object with priority 3. I then change it's priority to 10 during game play with "object:setPriority(10)". What do I do next when calling "updateRenderOrder" to permanently set this object's (and this object only) new priority to 10?

It is necessary to understand the drawing order MOAIProp, of MOAILayer.
Flower is an extension of the MOAILayer and MOAIProp.
Therefore, it is the same as the code of MOAI standard.

SortMode of MOAILayer Do you understand?
properties that are sorted by the constant set to sortMode changes.

http://getmoai.com/docs/class_m_o_a_i_layer.html#a50f5e62082ddf21b7cb30eb28acaf522

UpdateRenderOrder of TileMap sets in order Priority simply.
Therefore, if you set the layer to SORT_PRIORITY_ASCENDING, drawn according to the order of the layer.

In addition, TileObject is to update the priority by Y position.
Therefore, priority is TileObject change when you move.

"setSortScale" was the final missing piece of the puzzle. I wasn't aware that the default was changed from priority to Y. I feel stupid now, but thank you ever so much for taking your time to explain it to me.