SDL sprites leaving trails....

Started by
5 comments, last by fireside 18 years, 5 months ago
I'm having a problem where the image does not clear when the screen updates. After the sprite moves, the last frame is still there underneath it. Could someone check my source code and tell me what I'm doing wrong? http://nayusdante.mybesthost.com/hosted/sprite_problem.zip Ignore all the cpp files but main.cpp, as they are all blank. I apologize for any messy areas of the code, I haven't gotten around to cleaning up everything yet.
Advertisement
Looks like you aren't clearing the last frame. You need something like this:

SDL_FillRect(screen, NULL, 0);

after the flip. That'll erase everything that's on the screen buffer and give you a blank (black) canvas.
I like the DARK layout!
Awesome! Thank you for pointing that out. I would have never thought of filling the screen.
Let me guess, you went through the Cone3D tutorials?
Rob Loach [Website] [Projects] [Contact]
No, I'm just working command by command. I figure out what I want to do, look at several tutorials, then decide the best way to implement it in what I'm doing. I tried using some online tutorials as guides, but none of them really teach you what you're doing. I've learned a LOT more by setting my own goals and finding ways to accomplish them without being led by the hand.
Quote:Original post by Nayus Dante
No, I'm just working command by command. I figure out what I want to do, look at several tutorials, then decide the best way to implement it in what I'm doing. I tried using some online tutorials as guides, but none of them really teach you what you're doing. I've learned a LOT more by setting my own goals and finding ways to accomplish them without being led by the hand.


I don't know about going it _all_ on your own. The way I learnt to program was by following what they say in a guide and then trying to change/mess around with it so that it does expected results. It's more fun that way. :P
Out of curiosity, what's wrong with the cone3d tutorials? I'm using his sprite class right now which seems to be working very well. It uses a background replacement method rather than a fill, I think.

Oh wait, that's right. There was an error in the code where it was getting the width twice instead of getting the width and height and leaving trails. Other than that, I think it's a nice sprite system for small games.

I think there's a lot to said for using cone3d's tutorials. You get a nice sprite class, and yet you'll end up learning alot because it won't exactly fit your application. I decided to use SDL_image instead of the bitmap load. Made those changes. Found out the alpha channel didn't work, learned more. Saw the trails, and had to adjust that. All the while using a fairly proven and general framework that will be more reusable than if I started from scratch.

[Edited by - fireside on November 6, 2005 12:07:41 PM]

This topic is closed to new replies.

Advertisement