2D Sprite Rendering
Hi all, I am developing a 2D sprite game for my university coursework using DirectX 10 and C++.
I have spent a lot of time and late nights making this game and i just cannot get my head round rendering the sprites in a specific order. I mean every sprite in the class has their own Z axis value and the render class is called in order of when i want my sprites to appear but i just cannot figure out why they keep overlapping each other in different orders... The most irritating part is the background image appearing right at the front.... everytime i compile the render order is different every time....
Does anyone have any theories on this ?
Jamie
A sample of code from my Resources function:
...and a small bit from my Render function:
GameBGSprite = new SuperSprite(g_pD3D,"GameBG.png");GameBGSprite->Show();GameBGSprite->SetSpawnSize(1600,1200);GameBGSprite->SetSpawnLocation(400,300);GameBGSprite->zAxis = 0.1f;HUD1Sprite = new SuperSprite(g_pD3D,"HUD.png");HUD1Sprite->Show();HUD1Sprite->SetSpawnSize(800,110);HUD1Sprite->SetSpawnLocation(400,55);HUD1Sprite->zAxis = 0.2f;Target1 = new SuperSprite(g_pD3D,"Target.png"); //TargetsTarget2 = new SuperSprite(g_pD3D,"Target.png");Target3 = new SuperSprite(g_pD3D,"Target.png");Target4 = new SuperSprite(g_pD3D,"Target2.png");Target1->Show();Target1->SetSpawnSize(64,64);Target1->zAxis = 0.2f; Target2->Show();Target2->SetSpawnSize(64,64);Target2->zAxis = 0.2f; Target3->Show();Target3->SetSpawnSize(64,64);Target3->zAxis = 0.2f; Target4->Show();Target4->SetSpawnSize(64,64);Target4->zAxis = 0.2f;CrossHair = new SuperSprite(g_pD3D,"sprite.png");CrossHair->SetSpawnLocation(400,300);CrossHair->Show();CrossHair->SetSpawnSize(64,64);CrossHair->zAxis = 0.3f;
...and a small bit from my Render function:
switch (game_state) { case GS_MENU: //Menu Background MenuBG->Render(g_D3DSprite); //Help Menu HelpMenuSprite->Render(g_D3DSprite); break; case GS_PLAY: //Render All Game Play Stuff UpdateText(); GameBGSprite->Render(g_D3DSprite); Target1->Render(g_D3DSprite); Target2->Render(g_D3DSprite); Target3->Render(g_D3DSprite); Target4->Render(g_D3DSprite); CrossHair->Render(g_D3DSprite);
I'm not sure where this SuperSprite class is coming from (Google suggests is some kind of custom library?), but I'm gonna make a guess that the ZBuffer is disabled if you're seeing different kinds of overlaps at each run. If you have access to the rendering code, make sure the depth buffer render state is enabled and if it's using ID3DXSPRITE underneath, that this is set to repect your render states.
Again, I'm not familiar with this SuperSprite class, so without knowing what it really does it could be anything. I'd imagine that if you render partially transparent sprites enabling the ZBuffer won't work and you'd have to define some kind of draw order, but that's just more guessing.
Ah apologies with the SuperSprite name, it was the name of the sprite class my programming tutor came up with at the time when teaching us it.
Yes the Zbuffer sounds like it could be something to look at.
Is that any help at all ?
Yes the Zbuffer sounds like it could be something to look at.
Is that any help at all ?
Quote:Yes the Zbuffer sounds like it could be something to look at.
Is that any help at all ?
Well, you tell me [smile]
If you're looking for further advice on the issue, I suggest you post the code for SuperSprite::Render so we can see what it's actually doing. ID3DXSPRITE has some options to do sorting, the SuperSprite itself might be doing some sorting and there are quite a few renderstates that might have some influence on the issue.
However since your tutor has come up with this SuperSprite class as I understand, he should know if this is a common problem. Maybe something is off with the class or maybe you're not using it correctly. Whichever might be the case, your tutor is probably in a much better position to help you out with this issue than we are.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement