Azerty560
Azerty560

Reputation: 125

How to Draw above a picture in VB.NET

I am building a 2D game where the user is a circle(:P) and the enemies are rectangles coming at him. However, my problem is that when I placed a very nice picture of space I found on the internet, the screen draws whatever it has to underneath this image. Everything works,I can still see my lives going down when something collides into me - except the fact it is all covered up by this picture.

In a nutshell, my question is: How Do I Draw everything ON Top of this - (I tried using the 'Send To Back' Command)

EDIT: The form draws everything through a timer, and the user controls his character through keys. This probably won't help - but if it does it's here. Sorry folks didn't think you'd need the code. Here it is:

In the mybase.load procedure: PicBackGround.Dock = DockStyle.Fill PicBackGround is the picture box with the image.

In the paint procedure:

 e.Graphics.Clear(Color.Black)
        e.Graphics.FillEllipse(Brushes.Orange, Player)

        'Projectiles
        Dim i As Integer = 0
        Do
            If Current_Projectile(i).IsEmpty = False Then e.Graphics.FillRectangle(Brushes.Red, Current_Projectile(i))
            i += 1
        Loop Until i = UBound(Current_Projectile)

        'Objects
        i = 0
        Do
            If Objects(i).IsEmpty = False Then e.Graphics.FillRectangle(Brushes.Blue, Objects(i))
            i += 1
        Loop Until i = UBound(Objects)

Okay: Player is a rectangle declared right at the top, Dim Player As New Rectangle(0, 0, 50, 50); There is then the array Objects, which stores all the data about the enemies coming at the player, Current_Projectiles is simply an array to store data about rectangles(bullets) that the player fires.

Anything else you want to know just let me know.

Upvotes: 0

Views: 2449

Answers (1)

Hans Passant
Hans Passant

Reputation: 941277

Yes, a control overlaps anything you draw on the form. A simple solution is to use the form's BackgroundImage property instead. Or draw the image yourself.

Upvotes: 2

Related Questions