Archived

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

C# :: Mother Flicker!

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

hi... I've wrote this 'game' in C#, but i just can't get rid of the flickering. I do know why the flickering occurs, but the thing is that all of the tutorials on the internet explaing how to get rid of it, but only if you're using images and such... here's how my game works: i create a two dimensional array (labels), each being 12x12 pixels. the array is 20X40, and the first row (top) is made of randomly added bombs. then, the bombs drop down to the bottom row (i just copy each row, from bottom to top, erasing the top one)... anyhoo, so i have a timer that fires this, so bombs (or X's) just keep on dropping down the screen... and since I'm only using labels, i just don't know how to remove that flickering junk. can anyone please help me?! here's my game: http://www.mvhsbreakers.com/game.zip thanks! [edited by - pimple on October 15, 2003 8:41:27 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Nice idea for a game!!!!! i had fun with it, and i see no flickering at all, now u just have to make it more graphic

Share this post


Link to post
Share on other sites
well, if i increase the speed of the bombs or if you just hold down one of the arrow keys, you''ll see some flickering...
i''m going to implement that game quite a bit, but i just want to make it run smoother (graphically)... then after i''m done with that, i''ll add bitmaps and such...

thanks...

Share this post


Link to post
Share on other sites
bitmap blting code will most liekly need to be implemented quite differently than the way you are using labels. If you use graphical blting you can employ a technique called double buffering which will prevent flicker. As it stands labels just weren''t designed for smooth movement.

Share this post


Link to post
Share on other sites
I'm not familiar with C#, but I may have found a "Bug" in your game. If you move the cursor over, I think 22, bombs will never hit you. It may be 23, but I tried this 3 times, and blocks never fall on that line.

[edited by - PumpkinPieman on October 15, 2003 12:41:21 AM]

Share this post


Link to post
Share on other sites
As you probably know the flickering is refresh. I wrote a game in C# using GDI+ and could not for the life of me get rid of the flickering. The method I finally did manage to use to resolve it was switching to Managed DirectDraw. It''s very easy to work with and gets rid of annoying flicker.

Share this post


Link to post
Share on other sites
alright then, thanks...
concerning the post before yours... yeah, i just noticed how bombs will never drop on that one colum... that''s weird since i use Random.Next to make that first row... anyhoo, i''ll just see what i can do with directdraw then, and i''ll post in the future in case i have any success...

btw, after watching reloaded yesterday, i had this great idea... i''ll just make the background black, and the boms green, and instead of X''s, i''ll just randomly generate other characters (like the ones used in the matrix), and the brightness of the characters will also vary... so you''ll look pretty cool (hopefully)... i don''t know, maybe i''ll call my game something like "Matrix: XP"

Share this post


Link to post
Share on other sites
I did this too with gdi+ now I know there is a .doublebuffer in the gdi+ somewhere...
ahh found it

put this in your constructer for the form


SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);


really all you need is the last one for double buffering.

Share this post


Link to post
Share on other sites
@jperalta
even with GDI you can remove flickering. The technique is exactly like the one used by DirectDraw, use a secondary buffer.

@pimple
Flickers occur when the screen is updated before your game finishes its drawing. For example, your game is supposed to draw 100 bombs, but on the 10th bombs, for example, the screen refreshes. So, for x miliseconds you see 10 bombs, for the next x miliseconds you see 40 bombs, for the next next x miliseconds you see 100 bombs. This results in flickering. Especially that you use labels, everytime you update the contents of a label, C# will update the screen.

To remove it, you need to have a secondary buffer which is not displayed on the screen, but you can treat it as the monitor screen (it''s sometimes called Offscreen surface or Backbuffer). What you basically do is to draw everything on the secondary buffer, after everything is drawn, you update the screen by copying everything on the secondary buffer to the screen. See, the process of updating only occurs once, instead of 100 times.

Share this post


Link to post
Share on other sites
oh, okay... thanks for the help!
here''s the "finished" version of my project:

http://www.mvhsbreakers.com/DodgeTheMatrix.zip

it still flickers, but i''ll try to fix that ASAP, since i now kno what to do (sort of)...
thanks again

Oh, BTW, some people (my friends) weren''t able to play the game... it failed to initialize... does anyone know why it runs fine in some machines, but not at all in others?

thanks yet again...

Share this post


Link to post
Share on other sites