0
Answer

Flicker problem in simple directdraw animation

i've managed to put together the piece of code below and my aim was to create few moving objects on colorful background. the code works very slowly and picture flickers a lot and as i am very beginner in directx and c# i know i am missing something and douing some horrible mistake either with flags setting or some other silly thing. the code is below and i would appreciate if something would point out how to fix the problem and make the animation smooth. thx in advance ;) private void InitDirectDraw() { SurfaceDescription desc = new SurfaceDescription(); // Describes a surface. draw = new Device(); // Create a new DirectDrawDevice. draw.SetCooperativeLevel(this, CooperativeLevelFlags.FullscreenExclusive); // Set the cooperative level. draw.SetDisplayMode(widthScreen, heightScreen, 32, 0, false); // Set the display mode width and height, and 16 bit color depth. desc.SurfaceCaps.PrimarySurface = desc.SurfaceCaps.Flip = desc.SurfaceCaps.Complex = true; // Capabilities of the surface. desc.BackBufferCount = 1; // Create 1 backbuffer. front = new Surface(desc, draw); // Create the surface using the description above. desc.Clear(); // Clear out the SurfaceDescription structure. desc.SurfaceCaps.BackBuffer = true; back = front.GetAttachedSurface(desc.SurfaceCaps); // Get the attached surface that matches the caps, which will be the backbuffer. desc.Clear(); // Clear out the SurfaceDescription structure. desc.SurfaceCaps.OffScreenPlain = true; ColorKey ck=new ColorKey(); ck.ColorSpaceHighValue = 10066329;//RGB(153, 153, 153); ck.ColorSpaceLowValue = 10066329; //RGB(153, 153, 153); desc.Height=34; desc.Width=34; surfaceAnimation = new Surface("C:/C++/VisualStudio/Project/Images/ball_blue.bmp", desc, draw); surfaceAnimation.SetColorKey(ColorKeyFlags.SourceDraw, ck); //set the color key for the surface // background surface desc.Clear(); SurfaceDescription desc2=new SurfaceDescription(); desc2.SurfaceCaps.OffScreenPlain=true; desc2.Height=480; desc2.Width=640; surfaceAnimation2 = new Surface("C:/C++/VisualStudio/Project/Images/background1.bmp", desc2, draw); } public void drawdx() { for(int x=0,y=0;x<100;x++,y++) { back.ColorFill(0); back.DrawFast(0,0, surfaceAnimation2, new Rectangle(0,0,640,480), DrawFastFlags.Wait); back.DrawFast(x,y,surfaceAnimation, new Rectangle(0,0,34,34),DrawFastFlags.SourceColorKey | DrawFastFlags.Wait); front.Flip(back, FlipFlags.Wait); } }