|
trail |
neil dwyer
Member #7,237
May 2006
|
In my pong game. I want to have the ball leave a trail of putpixels. The only problem with this is that I am clearing the buffer every loop so the putpixel from the previous loop does not stay. Anyone have an idea to get around this. |
SonShadowCat
Member #1,548
September 2001
|
Make a particle class and use it to leave a trail, that way it gets treated like every other object and is redrawn. |
neil dwyer
Member #7,237
May 2006
|
The old pixels would still be cleared from the buffer, no? Edit: is there a way to clear certain objects from a bitmap without clearing the whole bitmap. |
Elverion
Member #6,239
September 2005
|
Yes, the "old" pixels will be cleared when you clear your frame buffer, but you will be redrawing. What you could do is record the last 10 frames' (x,y) coordinates for the ball. Then, in your drawing, you would redraw all 10 frames using the ball's bitmap, but you could also add alpha blending. Here is an example of what I'm talking about. Our point structure, so we can easily manage 2D points typedef struct Point2D { int x; int y; }; Declare our array of trails #define MAX_TRAILS 10 Point2D BallTrail[MAX_TRAILS+1]; Our drawing method for ball
You will need to go through and pound out a few of the minor things (such as fully initialising the array), and this code is untested, but at least it gives you the idea. -- |
Audric
Member #907
January 2001
|
I don't know if either explaination makes it clear or not, but the goal is to keep in memory enough information to redraw the trail. Quote: is there a way to clear certain objects from a bitmap without clearing the whole bitmap.
The dirty rectangle system (DRS) is a programming technique to do it. The Allegro demo game has an implementation. |
neil dwyer
Member #7,237
May 2006
|
Ok since my physics are non-existent(ball_x adds until it hits the paddle, then it subtracts;ball_y adds until it hits the wall then it subtracts) I declared 10 variables(5 for the five pixel's x values and 5 for the y's). It would of made sense to make a tail[5][2] but I wasn't thinking about clean code. Tail1 is always equal to the middle of the ball. If the ball_x is adding, then the next tail's x value is ball_x - 5. I had the idea to make the program "remember" where the ball has been from 5 frames before but I didn't know how to do it. I'll look in to elverion's idea. |
|