DireXt 9.0c moving Sprites not Loading unlike statics one. Why? Async position-SpriteLoad time maybe?

Started by
5 comments, last by esgol 12 years, 2 months ago
Please somebody explains me or if at least has any idea why this happens.

http://img687.imageshack.us/img687/9176/tempbugdirext.jpg

The code cant be more clear and straight, I look and re look and cant find something.
Sometimes, the stone sprite may load, but (!) simoultanousley its BLACK one is loaded, AND (!) the black one its the real that gives victory, if u go to the sprite one it simply disapears and nothings happens (!) What the hell "Ghosts in the machine"?!!
Could it be an asynchronized called of the Painter compared to position changing? However I call the painter after all position changes are done

Also the 2 static spritsew down right dont load however u can go there its an active location. That though not of my interest it EVEN MOST crazy

Please give an idea at least I've made this problem as more analysed and easy to understand I could even by making that Photoshop illustration.

DIRECT SCENE PAINTING

void Labyrinth_Painter()
{
int i=0, j=0, NewX=0, NewY=0;
RECT rectObst, rectPath, rectM, rectL, rectO, rectMWon;
if (d3ddev->BeginScene())
{

//erase the entire background
d3ddev->ColorFill(backbuffer, NULL, D3DCOLOR_XRGB(0,0,0));

//d3ddev->StretchRect(back, NULL, backbuffer, NULL, D3DTEXF_NONE);


//draw the sprite
//d3ddev->StretchRect(kitty_image[kitty.curframe], NULL, backbuffer, &rect, D3DTEXF_NONE);

for (i = 0; i <20; i++)
{
for(j = 0; j < 50; j++)
{
if (Labyrinth[j]=='*')
{
d3ddev->StretchRect(Obstacle_Image, NULL, backbuffer, &rectObst, D3DTEXF_NONE);
rectObst.left = Obstacle.x+NewX ;
rectObst.right = Obstacle.x + Obstacle.width+NewX;
rectObst.top = Obstacle.y+NewY;
rectObst.bottom = Obstacle.y + Obstacle.height+NewY;
}
if (Labyrinth[j]=='.')
{
d3ddev->StretchRect(PathImage, NULL, backbuffer, &rectPath, D3DTEXF_NONE);
rectPath.left = PathBlock.x+NewX ;
rectPath.right = PathBlock.x + PathBlock.width+NewX;
rectPath.top = PathBlock.y+NewY;
rectPath.bottom = PathBlock.y + PathBlock.height+NewY;
}

if (Labyrinth[j]=='M')
{
d3ddev->StretchRect(MpamphsImage, NULL, backbuffer, &rectM, D3DTEXF_NONE);
rectM.left = Mpamphs.x+NewX ;
rectM.right = Mpamphs.x + Mpamphs.width+NewX;
rectM.top = Mpamphs.y+NewY;
rectM.bottom = Mpamphs.y + Mpamphs.height+NewY;
}

if (Labyrinth[j]=='L')
{
d3ddev->StretchRect(LuciusImage, NULL, backbuffer, &rectL, D3DTEXF_NONE);
rectL.left = Lucius.x+NewX ;
rectL.right = Lucius.x + Lucius.width+NewX;
rectL.top = Lucius.y+NewY;
rectL.bottom = Lucius.y + Lucius.height+NewY;
}
if (Labyrinth[j]=='O')
{
d3ddev->StretchRect(PetradiImage, NULL, backbuffer, &rectO, D3DTEXF_NONE);
rectO.left = Petradi.x+NewX ;
rectO.right = Petradi.x + Petradi.width+NewX;
rectO.top = Petradi.y+NewY;
rectO.bottom = Petradi.y + Petradi.height+NewY;
}

NewX=NewX+21;
}
NewY=NewY+21;
NewX=0;
}
//if (MpamphsWon==true || LuciusWon==true)
//{
d3ddev->StretchRect(MpamphsWonImage, NULL, backbuffer, &rectMWon, D3DTEXF_NONE);
rectMWon.left = 0 ;
rectMWon.right = 1046;
rectMWon.top = 400;
rectMWon.bottom = 460;
//}
//stop rendering
d3ddev->EndScene();
}
}



FILE READ

void File_Reader(char **Array)
{
int i=0,j=0;
char *mystring;
mystring=(char*) malloc (52* sizeof(int));
FILE * pFile;
pFile = fopen ("LavirintosNDE.txt" , "r");

while ( (fgets (mystring , 52 , pFile) != NULL) && i<20 )
{
for(j = 0; j < 50; j++)
{
Labyrinth[j] = mystring[j];
}
i++;
}
}


SPRITES INITIALIZATION
Obstacle_Image = LoadSurface ("Wall2.bmp", NULL);
PathImage = LoadSurface ("Path2.bmp", NULL);
MpamphsImage = LoadSurface ("Mpamphs.bmp", NULL);
LuciusImage = LoadSurface ("L.bmp", NULL);
PetradiImage = LoadSurface ("O.bmp", NULL);
back = LoadSurface("Menu.bmp", NULL );
BackMpamphsWon = LoadSurface("bcgkMPAMPHS.bmp", NULL );
BackLuciusWon = LoadSurface("bcgkLUCIUS.bmp", NULL );


Obstacle.x = 0;
Obstacle.y = 0;
Obstacle.width = 21;
Obstacle.height = 21;
Obstacle.curframe = 0;
Obstacle.lastframe = 0;
Obstacle.animdelay = 2;
Obstacle.animcount = 0;
Obstacle.movex = 0;
Obstacle.movey = 0;

PathBlock.x = 0;
PathBlock.y = 0;
PathBlock.width = 21;
PathBlock.height = 21;
PathBlock.curframe = 0;
PathBlock.lastframe = 0;
PathBlock.animdelay = 2;
PathBlock.animcount = 0;
PathBlock.movex = 0;
PathBlock.movey = 0;

Mpamphs.x = 0;
Mpamphs.y = 0;
Mpamphs.width = 21;
Mpamphs.height = 21;
Mpamphs.curframe = 0;
Mpamphs.lastframe = 0;
Mpamphs.animdelay = 2;
Mpamphs.animcount = 0;
Mpamphs.movex = 0;
Mpamphs.movey = 0;

Lucius.x = 0;
Lucius.y = 0;
Lucius.width = 21;
Lucius.height = 21;
Lucius.curframe = 0;
Lucius.lastframe = 0;
Lucius.animdelay = 2;
Lucius.animcount = 0;
Lucius.movex = 0;
Lucius.movey = 0;

Petradi.x = 0;
Petradi.y = 0;
Petradi.width = 21;
Petradi.height = 21;
Petradi.curframe = 0;
Petradi.lastframe = 0;
Petradi.animdelay = 2;
Petradi.animcount = 0;
Petradi.movex = 0;
Petradi.movey = 0;

//initialize the sprite's properties


//return okay
return 1;
Advertisement
1. I'd check that all the surfaces used by StretchRect() are valid (I.e. not NULL).
2. You *really* shouldn't be using StretchRect; you should be rendering your sprites with the ID3DXSprite interface, or by rendering them yourself as textured quads (Which is what ID3DXSprite does internally). StretchRect may not be hardware accelerated, and doesn't allow you to use alpha blending, rotation, or any number of other things you get for "free" when using textured quads.
All of them are declared as NULL to the 2nd parameter if that what you mean. But they still work instead of the moving ones :S
That's not the surface, that's the source rectangle, and NULL means "Entire surface". I'm referring to the first parameter - check with your debugger that they're all valid at the time StretchRect() is called.
Well you wont believe it and its crazy how i solved it out

It doesnt draws THE LAST sprite so those 2 angles, since they were the last Path_Sprite and the last Wall_Sprite respectively they werent drawed.

The players since they are the uniqie sprites respectively they re not drawned also.

So Ive put down right and into a suplementary line one symbol from each sprite symbol uselesly, and so all previous are draw and everybody is happy smile.png

labyrinth2n.jpg

But I still cant figure out what is this madness. WHY NOT DRAWING ONLY THE LAST SPRITE SPECIFICALLY?

P.S.
Sorry, I felt the need to provide the solution to terminate the thread, Im not the type who comes like an egoistical monster seeking solution and shits all once got it.
( Yes its from Athens Technological Educational Institute in Greece. We do stuff too here, we re not just lazy PIGS going bankrupt and living on Loans, blame only our political system ;)
It's appreciated that you provided the solution, it's helpful in case someone comes across this thread in the future :)

I'm really not sure why your solution works; it might be worthwhile trying to create a minimal example that reproduces the bug - e.g. modify the code so it only draw 2 tiles and see if the second tile isn't drawn. Then you should hopefully be able to narrow the issue down a bit.

Also, if you've not already - I'd recommend using the debug DirectX runtimes; you can select them from the DirectX control panel (In start menu -> DirectX SDK -> Tools). That way, if a D3D call is failing for some reason (bad pointer, not supported, etc) you should get some useful output displayed in Visual Studio's output window.
Yes I hate the half threads were the poster found the solution and deserted it indifferent like an egoistical indiferent beast.
And you go study all the thread to reach half answer. This has to stop.

Thank you its a good idea cause in the example there wasnt such prob. Im fine since it works like this at least, but i ll have to figure out the prob otherwise i will find it in front of me sooner or later again re resolvable or not :/ Thank you

Oh really i didnt knew thanks for the advice

This topic is closed to new replies.

Advertisement