Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I program a moving car and a bike in a road with mountains but the moving car is having afterimages, when I put a cleardevice() function the afterimages will be removed alongside with its background.

What I have tried:

I tried searching for solution but I cant find any.
Posted
Updated 2-May-23 8:56am
Comments
Richard MacCutchan 2-May-23 12:51pm    
Every time the car moves, you must first repaint the background before painting the car at its new position.

If you're talking about rendering an animation, you have to redraw everything EVERY FRAME of the animation, with objects in their new locations, like your car. You cannot just "remove the car" and expect it to reveal the background. Once you draw the car, there is no backgroun under it. "Removing" the car will just leave a car shaped black hole where the car used to be.
 
Share this answer
 
To add to what Dave has - rightly - said, the way I'd do it is to have a background image which I copy each frame, then draw the car onto the copy at each it's current position. Then swap the current image for the new copy and it'll appear to move without any ghosting.

This means keeping three screen images: the one being displayed, the background, and the "spare" - you do not want to start allocating new images, particularly if they are the size of the screen - that will seriously impact performance pretty quickly!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900