need SMOOTH animation...why must mine flicker???
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.
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."
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."
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...
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 ^^
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 ^^
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.
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."
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.
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.
quote:Original post by RuneLancer
Just drawing on an offscreen surface and then copying it is pointless;
Actually, it''s not - you get 0% overdraw this way, and therefore minimise the amount of data you send across the video bus.
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement