BeforeDraw event

Jun 4, 2013 at 5:18 AM
Hi guys,

Been working with the engine for a while and its very effective and easy to use,

Getting an issue trying to figure out how to convert the information on that thread :

http://tide.codeplex.com/discussions/250463

To make it work under vb.net, so i can draw my player between 2 layers of the map.

Been searching for vb example but didnt found anything similar with the engine, hope someone got info that could help =)

thanks in advance !
Jun 4, 2013 at 8:11 AM
I converted the sample code with an online conversion tool I found here.
' hook event
m_map.Layers(3).BeforeDraw += OnBeforeLayerDraw


Private Sub OnBeforeLayerDraw(sender As Object, layerEventArgs As LayerEventArgs)
    Dim spriteBatch As SpriteBatch = m_xnaDisplayDevice.SpriteBatchAlpha

    ' do stuff here...

End Sub
Jun 4, 2013 at 4:39 PM
Thanks for the reply,

That's exactly what i tough fist but "m_map.Layers(3)." dont give me the beforedraw option, is it something im doiing wrong ?

thanks in advance
Jun 4, 2013 at 11:00 PM
Looks like that translator doesn't do it's job well. I did a quick search on event handling in VB.NET and it seems you have to do something like the following
AddHandler m_map.Layers(3).BeforeDraw AddressOf OnBeforeLayerDraw
instead of
m_map.Layers(3).BeforeDraw += OnBeforeLayerDraw
I admit I haven't touched VB.NET in 8 years or so!
Jun 5, 2013 at 4:20 AM
Thanks that did it and been able to trigger the event, here the exact syntax :
AddHandler Map.Layers(1).BeforeDraw, AddressOf OnBeforeLayerDraw
Is there some example somewhere of player drawing with the event ? Cause i was using it under my World class to render the map and the player but now i cant figure out how i can change the player direction =)

thanks a lot again !
Jun 5, 2013 at 7:11 AM
Check my response to this thread. It details how to convert your player's world coordinates to viewport coordinates. For further info, you probably need to look up some platform game dev tutorials.
Jun 6, 2013 at 7:22 AM
Cool, ill check on that, thanks a lot !
Jun 13, 2013 at 3:52 AM
Sorry for the delay to get back with the answer on the layer part,

What im trying to do is to draw my player on the second layer of the map so that he can walk behind stuff on third one,
To make that i've add the beforedraw event as you suggest, on the event i've had the player drawing part there,

With that i'm still unable to walk on the good layer, ive even tried to add an empty layer but same thing, player always on top of everything,

Not sure what im doiing wrong in there, hope the description is good enough to help you diag my thing =)

thanks again in advance.
Jun 13, 2013 at 8:40 AM
You need to make sure that you draw your sprites within BeforeDraw using either of the SpriteBatch instances provided by XnaDisplayDevice. These are accessible as properties SpriteBatchAlpha and SpriteBatchAdditive. Check the code in the demo source here (look for the falling leaves drawing code in the OnBeforeLayerDraw handler method).