Sign in to follow this  

I made a better sprite engine, help me improve it more!

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

Some might remember some time ago where I first attempted to use sprites. Well, I got some suggestions for how to improve my sprite engine, and made another Dancing Kirby! Check it out! Please comment on how I could improve it more (besides error handling, I know there is none and I will add some later). So far I added an intermediate image class that can draw itself, an animation loader that uses a binary file format that I made, and sprites that can have different delay times so they run at different speeds. The only problem is that the sprites color keying messed up (they all draw on black instead of the background I made). Check it out! _________________________________________________________________________________

Share this post


Link to post
Share on other sites
Great job man! Here's how to fix that problem of the keying messing up:

void cSprite::ClearArea()
{
SDL_FillRect(SpriteSheet->Dest, &BoundingBox, SDL_MapRGB(SpriteSheet->Dest->format, 0, 0, 0));
}


In that function, you clear the last region that the sprite was in. However this is not needed because you redraw the background everyloop then draw all of the sprites. Now if you comment the SDL_FillRect out, you will see some black artifacts on your sprites. This from the way the sprites are done, not your code. So you should be able to take out that function call and fix your sprites so the black specks do not show anymore.

I will take a further look a bit later, I just wanted to point that out as well as say nice work [wink]

Share this post


Link to post
Share on other sites
Thanks for the reply Drew_Benton!
I took out the SDL_FillRect in the function you mentioned and it showed the black artifacts. But I can't figure out how to redraw it to a transparent color, I tried making the fill color 0, 255, 0 (pure green) which is the color that I color keyed it to ignore, but it doesn't ignore it. Could you elaborate please?

EDIT: Oops, you were replying as I wrote this.

Share this post


Link to post
Share on other sites
If you follow the framework set forth in the book "Focus on SDL" (Great book. Great author.) you would have a class that managed all your sprites for you. I.E. The class would keep a list or an array of all the sprites, and when you call that class' update function, it will call all your sprite's update functions. Just a suggestion so that you don't have to call every sprites update function in the main loop -- just the Sprite manager's update function.

-Brice

Share this post


Link to post
Share on other sites
For another quick idea. Your problem with the sprites is that they are not all the same size and at the same offest. In your function:

void cImage::Draw(int Animation, int Frame)
{
Dimensions.x = Frame * Width;
Dimensions.y = Animation * Height;
Dimensions.w = Width;
Dimensions.h = Height;

SDL_BlitSurface(Source, &Dimensions, Dest, &Location);
}




By changing:
Dimensions.w = Width - 2;
The black specks go away, but in some images the right end is cut off. This clarifies the fact the sprite set is at fault [smile].

Quote:
Original post by Drakkcon
Thanks for the reply Drew_Benton!
I took out the SDL_FillRect in the function you mentioned and it showed the black artifacts. But I can't figure out how to redraw it to a transparent color, I tried making the fill color 0, 255, 0 (pure green) which is the color that I color keyed it to ignore, but it doesn't ignore it. Could you elaborate please?

EDIT: Oops, you were replying as I wrote this.


Just saw that [wink]. What's happening is this, some of your sprites are offset some so in a few frames, it will grab the next frames beginning pixels. That is what is causing the black specks. You do not need to clear the area of the sprite in this instance because you are drawing a background over it every time. Does that make a little more sense? I will see if I can do some updating real fast.

Share this post


Link to post
Share on other sites
Okay, that's good. I'll just open up Paint later and swell the sprite borders by two pixels in every direction. I'm still having trouble with the color key though.

Quote:

If you follow the framework set forth in the book "Focus on SDL" (Great book. Great author.) you would have a class that managed all your sprites for you. I.E. The class would keep a list or an array of all the sprites, and when you call that class' update function, it will call all your sprite's update functions. Just a suggestion so that you don't have to call every sprites update function in the main loop -- just the Sprite manager's update function.

Thanks for the suggestion, the map class that I'm going to make later will have an std::list of all the sprites and update them like that.

Edit: @Drew_Benton: I understand now, thanks very much!

Share this post


Link to post
Share on other sites
Quote:
Original post by Drakkcon
Okay, that's good. I'll just open up Paint later and swell the sprite borders by two pixels in every direction. I'm still having trouble with the color key though.


Your color key is perfect! It takes all pixels that are Green, 0,255,0 and makes them transparent. I checked it to my old code and it is fine. Is there something else that you think is wrong with it, or was it just the black specks?

[edit]No problem [smile] For a few later updates you should make this all data driven [grin] Make it so you have some .xml/.ini file that the user can specify the transparent color as well as everything else, height, width, filenames, etc... Then you will just load this file in and everything else is done for ya automatically.

Share this post


Link to post
Share on other sites
Quote:

[edit]No problem For a few later updates you should make this all data driven Make it so you have some .xml/.ini file that the user can specify the transparent color as well as everything else, height, width, filenames, etc... Then you will just load this file in and everything else is done for ya automatically.


That's the next step :)

Share this post


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