Jump to content
  • Advertisement

Archived

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

ca_priest

need SMOOTH animation...why must mine flicker???

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

My game is a 2d rpg written in c. I had the game running at 60fps, but i tried all the way up to 300...and still, as my guy moves across the screen, he seems to be flickering/blinking. The walking looks good, its realistic and looks like that of an old snes game...but still it flickers. Im wondering if anyone knows why this is? Question: Everytime you need i redraw the character, and im using a new sprite, lets say on with the left leg forward when walking, i first erase the previous occurance of the character pixel by pixel, then i draw the new one, pixel by pixel. Is this my problem? Should i be somehow drawing every pixel that belongs to the character onto the screen simultaneously? Does anyone have any ideas on how i can get rid of this flickering??? Thanks in advance for any help.

Share this post


Link to post
Share on other sites
Advertisement
you need to know about double buffering and page flipping.
read this.
it''s for DOS, a little bit outdated, just read his explanation about double buffering and page flipping. Or read DirectX 7 Documentation (DirectDraw) if you have any.


My compiler generates one error message: "does not compile."

Share this post


Link to post
Share on other sites
Every PC''s monitor has this thing called a "refresh rate". Now I''m pretty sure you know what this is and therefore, you shouldn''t feel too confused by this...

Picture a monitor...


_______
| |
| |
| |
| |
¯¯¯¯¯¯¯
Now let''s suppose there''s a sprite on the screen.


_______
| |
| .. |
| .. |
| |
¯¯¯¯¯¯¯
The sprite animates to frame 2. However, flicker occures. What''s going on here? Well, what should''ve happened is...


_______
| |
| ... |
| . |
| |
¯¯¯¯¯¯¯
But the screen refreshes constantly. Thus, since the sprite is drawn while the screen refreshes, we see this... (the - is the refresh ''line'')


_______
| |
| ... |
---------
| .. |
| |
¯¯¯¯¯¯¯

How is this solved? Look into double-buffering. Basically, you''d draw stuff on a "screen" in memory and only show that screen when the "refresh line" reaches the bottom of the screen, so as to avoid having part of the screen be updated while the other part doesn''t change since it already has been updated.

Hope this helps ^^

Share this post


Link to post
Share on other sites
Ok what i did now was try and do this as follows: the sprite that needs to be drawn next, is first drawn on to a virtual bitmap, then when thats done, its blitted onto the screen. This is double buffering correct? However i still have the flicker just as i did before. So are you saying i should time the blitting to be in sync with the monitors refresh rate? Also...im actually doing this a few times. For example, the sprite is inbetween two tiles, so each of these tiles are blitted, then the character, but not all three at the same time...should i draw all three onto a virtual bitmap together, then blit that onto the screen, or dont i need to do this? One more thing...should i double buffer the whole screen or just what im drawing?? I have multiple npc''s walking around, as well as my character, so it would be better to constantly redraw the whole screen, or just individually blit each entity. Thanks for the reply and the advice.

Share this post


Link to post
Share on other sites
quote:
Original post by ca_priest
For example, the sprite is inbetween two tiles, so each of these tiles are blitted, then the character, but not all three at the same time...should i draw all three onto a virtual bitmap together, then blit that onto the screen, or dont i need to do this? One more thing...should i double buffer the whole screen or just what im drawing?? I have multiple npc''s walking around, as well as my character, so it would be better to constantly redraw the whole screen, or just individually blit each entity. Thanks for the reply and the advice.


you need to draw the whole thing, not separated objects, in the virtual bitmap, and then flip it. you never ever draw objects directly onto the screen (primary buffer).



My compiler generates one error message: "does not compile."

Share this post


Link to post
Share on other sites
That''s not exactly double buffering...

DirectDraw, for instance, handles double buffering like this...

1'' Programmer creates two surfaces; one that''s a pointer to the screen and one that''s a pointer to the offscreen bitmap.
2'' Programmer writes to the offscreen bitmap. He or she NEVER touches the screen itself.
3'' Once done, the programmer exchanges the offscreen bitmap pointer with the screen pointer when the refresh cycle is completed. DDraw handles this itself with DD_Surface->Flip();
4'' Go back to step 2.

Just drawing on an offscreen surface and then copying it is pointless; it''s like if instead of drawing a bunch of small sprites you draw one big image. You''ll still end up copying during the screen''s refresh period and getting flicker for it.

Share this post


Link to post
Share on other sites
He meant writing to multiple off-screen buffers, and copying them to the primary frame-buffer in order. This consumes more memory than just writing to the frame-buffer directly, and still causes flickering.

Share this post


Link to post
Share on other sites
Yea magmai you''re right...i was drawing to multiple off screen buffers and then copying them to the screen. At alnite''s suggestion i drew everything to a single full screen virtual bitmap, and then copyed the enitre thing to the screen. Now there is no flicker, even when i had about 20 npc''s all walkin around, plus my character. Thanks to all of you that replyed, my questions was completely answered and my problem is solved. Thanks again.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!