OnAfterLayerDraw / OnBeforeLayerDraw

Dec 4, 2012 at 12:23 PM

Hi together,

my Problem is, that an actor should hide another actor. But I am using the OnAfterLayerDraw / OnBeforeLayerDraw methods.

But I think the DrawOrder Property is useless if I use the OnAfterLayerDraw / OnBeforeLayerDraw delegates. Is there any possibility to draw between the layers with the normal Draw() method that is called automaticly by the Framework? How did you solve this problem?

But up to now I love tIDE and XTile :) Very nice, thanks.

Greetings from Germany.

 

Coordinator
Dec 4, 2012 at 12:42 PM

The OnAfterLayerDraw / OnBeforeLayerDraw delegates are there to allow you to draw between layers. For this to work, you need to use one of the SpriteBatch properties offered by the XnaDisplayDevice object (SpriteBatchAlpha and SpriteBatchAdditive), to ensure everything is rendered in the correct order. Using these spritebatch properties, draw order is determined by the order of drawing commands in the code.

Have a look at this discussion for more details.

Dec 4, 2012 at 1:00 PM

I have no problems in drawing the actor between the layers. The delegates solve this problem perfect.

I want to know if I can use the automatism of the Property DrawOrder of the DrawableGameComponent, because my actor inherits of DrawableGameComponent.

Little description:

By default, components are updated and drawn in the order they were added, and they are always updated and drawn. However, these are all changeable, too. If you set the DrawOrder property, when the components are being drawn, the components with the lower DrawOrder values are drawn first. Similarly, if you use the UpdateOrder property, the components with the lower UpdateOrder value are updated first. The higher value these properties have, the later they happen in the list of components. If you want something drawn as the last possible component, you set the DrawOrder to int.MaxValue, for example. Of course, if you have more than one component with the same UpdateOrder or DrawOrder, they are called in the order they were added.

So I think the DrawOrder Property is useless, because the delegates call the "OnAfterLayerDraw / OnBeforeLayerDraw" methods in the assignorder and not in the DrawOrder. And in the Draw() method which is automaticly called in the order of "DrawOrder" there isn't any drawcode anymore, because this code is in the "OnAfterLayerDraw / OnBeforeLayerDraw" methods.

Is this logic correct or did I misunderstand something?

My english is not perfect, I hope I could explain the problem.

Coordinator
Dec 4, 2012 at 1:15 PM
Hi,

Don't worry, your English is better than my German! :)

As you rightly pointed out, the DrawOrder property is useless in this case. This is really used by the Game's Draw method and in your own Game-dervied class, it only works at all if you call base.Draw(...) within your Draw method override. The base Draw method of the Game class takes care of rendering any attached drawable components, either in the order prescribed by insertion into the Components property, or by the DrawOrder as you indicated.

The xTile API does not bind very tightly with XNA and does not use XNA's DrawableGameComponent system. Indeed, the XnaDisplayDevice class is merely an XNA-based implementation for IDisplayDevice, which represents an abstract graphics device. The only capabilities assumed by this interface are the ability to load graphical resources via LoadTileSheet() and to render a given tile at a given display location where the render order is dictated by the order of tile render calls.

If you want to render the actor between layers, I suggest you avoid adding it to the Game's Components collection as this will interfere with the tile rendering engine.

Hope that helps!
Cheers,
Colin


On 4 December 2012 15:00, whiteday <notifications@codeplex.com> wrote:

From: whiteday

I have no problems in drawing the actor between the layers. The delegates solve this problem perfect.

I want to know if I can use the automatism of the Property DrawOrder of the DrawableGameComponent, because my actor inherits of DrawableGameComponent.

Little description:

By default, components are updated and drawn in the order they were added, and they are always updated and drawn. However, these are all changeable, too. If you set the DrawOrder property, when the components are being drawn, the components with the lower DrawOrder values are drawn first. Similarly, if you use the UpdateOrder property, the components with the lower UpdateOrder value are updated first. The higher value these properties have, the later they happen in the list of components. If you want something drawn as the last possible component, you set the DrawOrder to int.MaxValue, for example. Of course, if you have more than one component with the same UpdateOrder or DrawOrder, they are called in the order they were added.

So I think the DrawOrder Property is useless, because the delegates call the "OnAfterLayerDraw / OnBeforeLayerDraw" methods in the assignorder and not in the DrawOrder. And in the Draw() method which is automaticly called in the order of "DrawOrder" there isn't any drawcode anymore, because this code is in the "OnAfterLayerDraw / OnBeforeLayerDraw" methods.

Is this logic correct or did I misunderstand something?

My english is not perfect, I hope I could explain the problem.

Read the full discussion online.

To add a post to this discussion, reply to this email (tIDE@discussions.codeplex.com)

To start a new discussion for this project, email tIDE@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Dec 4, 2012 at 1:18 PM

If I'm at home later, I will test this.

Thank you for the help.