Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The thing is there are 3 shapes in my picture box a circle(Ellipse) and 2 Rectangles i want to only invalidate the circle is there a way to do that.

The circle goes up and down while rectangles move towards the left when the rectangles disappear 2 more show up

The first para is me making the colour and graphics
The second para is making the bird
the third para is me making 2 opposite walls which will always have space betweem them

However when i use my UpdateScreen function to make the bird move and create a video affect the bird moves however the walls move and respawn making it a jittery mess
A visual representation

A visual representation

https://youtu.be/zYg4GA5XeMw

What I have tried:

i have tried putting circle and rectangle in different methods when they are called but the command i use Canvas.Invalidate (Canvas being picture box) hence it refreshes the whole picture box
SolidBrush Yellow = new SolidBrush(Color.Yellow);
            Graphics Canvas = e.Graphics;

//Make Bird
            Canvas.FillEllipse(Yellow, Bird.X, Bird.Y, Settings.WidthBird, Settings.HeightBird);

//Make Bird
            //Max Height
            int MAxHeight = PbCanvas.Size.Height;
            int MH = MAxHeight - 80;
            int HeightD = random.Next(0, MAxHeight - 80);
            int HeightU = MH - HeightD;
            int Bottom = PbCanvas.Bottom;
            new Settings();
            //Walls
            Canvas.FillRectangle(Black, X, 0, 50, HeightU);
            Canvas.FillRectangle(Black, X, Bottom - HeightD, 50, HeightD);
                                      //X        //Y         //W  //H
Posted
Updated 25-Dec-18 5:02am
v6
Comments
[no name] 25-Dec-18 5:40am    
How is about with Shape.Invalidate​Visual() ?
NotAComputerScienceStudent 25-Dec-18 5:44am    
How do we do that? What do we have to write instead of "Shape"
[no name] 25-Dec-18 5:51am    
I assume you have something like
Ellipse myEllipse = new Ellipse();
in your code. So you can do
myEllipse.Invalidate​Visual()
when needed
NotAComputerScienceStudent 25-Dec-18 6:22am    
what should i be using. E.g. System.drawing etc
[no name] 25-Dec-18 6:24am    
I don't understand your question. Does the above not help? In case not you should extend your question with the relevant code snippets.

See tip here: Drawing on picture box images[^]
If this does not work, consider using another control like a Panel, as PictureBox is not really a good choice for custom drawing.
 
Share this answer
 
v2
The PictureBox is not designed for rendering games. It's a really poor choice for this.

You can "Invalidate" a shape, but that does not get the PictureBox to redraw the shape. You have to Invalidate the PictureBox which will cause the PictureBox to repaint, but ALL of the content in the control.

Since you have to do all of the drawing yourself anyway, a better choice would be a customized Panel instead. You'll still have to Invalidate the Panel to get it to draw itself, but you'll be handling the Paint event of the Panel and doing all of the drawing.

Games don't invalidate and draw individual objects. The usually redraw EVERYTHING on screen on every frame of the game you see.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900