• Advertisement
Sign in to follow this  

Drawing sprites problem

This topic is 2762 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

Hey guys, I'm drawing layered sprites using


This layers them as last drawn is on top.

The problem is that some of the sprites are either not being drawn, or they're being drawn underneat other sprites that they shouldn't be.

Here is an example of the draw code.

// Draw the character model
Soldier.Draw(m_pSprite, game.m_xPlayerModel, game.m_yPlayerModel);

// Draw the menu/frame

BorderStretch.Draw(m_pSprite, s_nWindowWidth-200, 0);

DrawMenu(game.m_menuID, m_pSprite, m_pFont, s_nWindowWidth, game.m_squad, game.m_fteam, game.m_menuFeedback);
Cursor.Draw(m_pSprite, s_nWindowWidth-50, 178+game.m_cursorLoc*20);

The map is drawn before this using a loop, then in the code excerpt it should draw the soldier sprite and (if the menu is up) the menu sprites and cursor.

The cursor is the last thing drawn, and thus should be on top of EVERYTHING else. The problem is about half the times I compile, it's not there. It's totally random. I can compile the same code multiple times and have the cursor show up sometimes and be hidden others.

Now, I haven't been able to determine any possible cause of this, but I HAVE determined that using Sleep(x) during the sprite.begin/end block will cause ALL the sprites after that to not be drawn (or be drawn underneath other sprites. Even if I sleep for only 1ms.

So, is there a time limit on how long the program can be inside the begin/end block?

Does anyone have any insight as to how/why this is happening?

Share this post

Link to post
Share on other sites
Well, after a few more hours of reading. I realized I may have a mental deficiency and that the sorting backtofront or fronttoback only sort by the Z value assigned to the sprite. All of my sprites had un-initialized Z values. Sorting by garbage for the lose.

I removed the D3DXSPRITE_SORT_DEPTH_BACKTOFRONT flag from the Begin() function and everything is peachy...for now.

Share this post

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

  • Advertisement