Sign in to follow this  
marrshal

XNA does not draw everything

Recommended Posts

I'm writing a simple game in XNA but some elements are not drawn to the screen. The code is too big to post it so I'm posting only the draw functions.

Main draw func:

[code]
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.LightGreen);

spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied);
base.Draw(gameTime);
spriteBatch.End();

//-Draw Cursor
spriteBatch.Begin();
if(scr_cursor.unit == null)
spriteBatch.Draw(scr_cursor.cursor, new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Color.White);
else
spriteBatch.Draw(scr_cursor.unit.small, new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Color.White);
spriteBatch.End();
}[/code]


Draw func of one of Properties_menu components:

[code]
public override void Draw(GameTime gameTime)
{
sBatch = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));


menus[mode].DrawIt();
sBatch.Draw(skin, position, Color.White);

base.Draw(gameTime);
}[/code]


And Menu.DrawIt():

[code]
public void DrawIt()
{
if (main_obj != null)
prop_menu.sBatch.Draw(main_obj, prop_menu.position + new Vector2(20, 20), Color.White);

prop_menu.sBatch.Draw(prop_menu.box_large, prop_menu.position + new Vector2(20, 20), Color.White);

for (int j, i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
{
prop_menu.sBatch.Draw(prop_menu.box_small,
prop_menu.position + new Vector2(i * 70 + 20, j * 70 + 160),
Color.White);
}
}[/code]

here prop_menu is set by [i]this[/i] in the Properties_menu constructor.

The result is attached.
[attachment=4237:img.JPG]

Why are not all small boxes drawn and how to fix this?

MarrShal

Share this post


Link to post
Share on other sites
Are you sure the [color=#1C2837][font=CourierNew, monospace][size=2][color=#000000]prop_menu[/color][color=#666600].[/color][color=#000000]position properties for the missing items are what they're supposed to be?[/color][/size][/font][/color]

Share this post


Link to post
Share on other sites
[quote name='Machaira' timestamp='1311165208' post='4837935']
Are you sure the [color="#1C2837"][font="CourierNew, monospace"][size="2"][color="#000000"]prop_menu[/color][color="#666600"].[/color][color="#000000"]position properties for the missing items are what they're supposed to be?[/color][/size][/font][/color]
[/quote]

[code]
for (int j, i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
{
prop_menu.sBatch.Draw(prop_menu.box_small,
prop_menu.position + new Vector2(i * 70 + 20, j * 70 + 160),
Color.White);
}
[/code]

This generates the positions of all elements. (prop_menu.position is the position of the whole menu)

Share this post


Link to post
Share on other sites
I found the problem. :)
Somehow in the middle of the night I decided not to draw [font="Lucida Console"]prop_menu.skin[/font] and I was wondered when I saw all of my small boxes drawn. So, because of the sprite priority first are drawn the "missing" boxes, then prop_menu.skin [font="Arial"]and in the end the "visible" boxes. To fix the problem I should just change[/font]
[font="Arial"]
[code]
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied);
base.Draw(gameTime);
spriteBatch.End();[/code][/font]
[font="Arial"]int the main Draw func to [/font]
[font="Arial"][code]
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
base.Draw(gameTime);
spriteBatch.End();[/code][/font]

[font="Arial"]and reorder some of the draw func calls. :)[/font]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this