Jump to content
  • Advertisement
Sign in to follow this  
marrshal

XNA does not draw everything

This topic is 2555 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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:


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();
}



Draw func of one of Properties_menu components:


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);
}



And Menu.DrawIt():


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);
}
}


here prop_menu is set by this 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
Advertisement
Are you sure the [color=#1C2837][font=CourierNew, monospace][size=2][color=#000000]prop_menu[color=#666600].[color=#000000]position properties for the missing items are what they're supposed to be?[/font]

Share this post


Link to post
Share on other sites

Are you sure the [color="#1C2837"][font="CourierNew, monospace"][color="#000000"]prop_menu[color="#666600"].[color="#000000"]position properties for the missing items are what they're supposed to be?[/font]



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);
}


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"]

spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied);
base.Draw(gameTime);
spriteBatch.End();
[/font]
[font="Arial"]int the main Draw func to [/font]
[font="Arial"]
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
base.Draw(gameTime);
spriteBatch.End();
[/font]

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!