Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Kosh

DirectDraw problems with corrupted sprites

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

hi everyone I have a little problem using DirectDraw and well, this is a good place to start asking, so.... I have a sprite game, based on space invaders (uh oh, hasbro watching me!!) and well, I have the sprites for the invaders, defense units and player sprite stored in IDirectDrawSurface4 *surfaces''s in video memory But my problem is, that when I run the game, it copies these master images from the video storage to the video memory that is displaying the screen. When I do this, I also have a star field in the background, this is being drawn all on the same buffer (secondary buffer). The order of drawing all this is Starfield Interface elements = score, highscore, lives, level number static sprites = Invaders, player, defense units dynamic sprites = weapons, explosions (static sprites meaning that they are there for the whole game, and either are destroyed for the entire level, or not) (dynamic sprites are fleeting sprites which dont stay onscreen for long, like weapons and explosion effects) Now, When I draw all this to the screen, it appears like the star field is corrupting the master images for the sprites, for some reason, when I blit the sprites to the secondary surface, they pick up all the stars beneath them and hence get corrupted. But I dont understand how this could happen. Does anyone know what I mean, does anyone need more information on this, please reply, cause this is REALLY bugging me kosh

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
More than likely it is the pixel plotting that you use for drawing the stars. You are probably changing memory outside the area of the back surface and altering the surfaces for the other sprites. If the res is 640x480, for example you can only draw from 639x479...
that one pixel difference is probably causing the problem.
(memory indexes is zero based so it is 0 - 639). And don''t forget to plot pixels using lPitch and NOT dwWidth.

Share this post


Link to post
Share on other sites
ok, in response to you I post up this source, cause this is the function that I am using to draw the stars ok



int RenderStars(IDirectDrawSurface4 *surface)
{
DDSURFACEDESC2 RenderStarsDesc;
memset(&RenderStarsDesc, 0, sizeof(RenderStarsDesc));
RenderStarsDesc.dwSize = sizeof(RenderStarsDesc);

if((surface->Lock(NULL, &RenderStarsDesc, DDLOCK_SURFACEMEMORYPTR / DDLOCK_WAIT,NULL)) == DD_OK)
{
int bytesperpixel = (int)RenderStarsDesc.lPitch;
unsigned int *buffer = (unsigned int *)RenderStarsDesc.lpSurface;

for (int i = 0; i < 250; i++){
buffer[(star_field.y * (bytesperpixel>>1)) + star_field[i].x] = star_field[i].colour;
}

if((surface->Unlock(NULL)) == DD_OK) return 1;
}

return 0;

}

Share this post


Link to post
Share on other sites
oh, by the way, I''m using 16bit colour, just in case you were wondering what the bytesperpixel>>1 meant, it''s dividing the lpitch by two, which gives me the exact number of pixels, rather than the actual memory used in those pixels

this is correct aint it?

kosh

Share this post


Link to post
Share on other sites

int bytesperpixel = (int)RenderStarsDesc.lPitch;


A better name for this might be bytesperline ...

unsigned int *buffer = (unsigned int *)RenderStarsDesc.lpSurface;


here''s your problem: you''re indexing an array of INTs which
are 4 bytes long. change to ''short'' (or even better, a ''sized'' typedef: typedef short uint16;)


for (int i = 0; i < 250; i++){
buffer[(star_field.y * (bytesperpixel>>1)) + star_field.x] = star_field[i].colour;
}


I assume you mean star_field[i].y, not star_field.y ...

Good luck.

--Pryankster

Share this post


Link to post
Share on other sites
hi

well Pryankster you solved my problem, by the way, it wasnt the array index, I dont know why, but I copied an old version by mistake (version checking anyone ) so it was in the middle of becoming array indexed

BUT !!! the problem with the four byte INT worked, I dont like Win32 typedefs, I think the make code a little less readable, I prefer ansi, so, I just changed it to unsigned short and AWAY !!

thanks to everyone who solved this problem, it''s not a problem anymore, no corruption in any sprite

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!