|
-
Feb 5th, 2013, 02:19 PM
#1
Thread Starter
Addicted Member
True transparent pictureboxes?
Hello awesome coders 
I have been making a Mario like side scrolling game and it is working quite well. The only problem I have encountered is when I walk pas an object on the background, you see the square pic box surrounding the player. So the object has a Control colored square with a mario on it. Is there a way to resolve this?
Thanks a lot in advance
-
Feb 5th, 2013, 03:24 PM
#2
Re: True transparent pictureboxes?
Yea, don't use PictureBoxes. 
No, seriously, it doesn't take much to get into the basics of XNA game programming, and you can load in graphics that have transparency (like PNG files) as sprite objects which you can do whatever you want with. Plus, they'll be hardware accelerated and flicker-free. On top of everything, you'll be learning how to make a game like a professional. It'll save you truck-tons of headaches later on.
-
Feb 6th, 2013, 09:20 AM
#3
Re: True transparent pictureboxes?
 Originally Posted by ikdekker
Hello awesome coders 
I have been making a Mario like side scrolling game and it is working quite well. The only problem I have encountered is when I walk pas an object on the background, you see the square pic box surrounding the player. So the object has a Control colored square with a mario on it. Is there a way to resolve this?
Thanks a lot in advance
The problem is that the transparent part of a PictureBox can only show you the parent control surface. That means you are seeing the background colour of the Form. You could set your Mario's Parent to be another PictureBox but that's not much use to you if you have multiple 'objects' in separate controls; only one control can be the Parent.
Instead, draw everything in the Paint event handler of one control, for example the form:
Code:
Private Form1_Paint(Sender As Object, e As PaintEventArgs) Handles Form1.Paint
e.Graphics.DrawImage(BackGroundImage, 0, 0)
e.Graphics.DrawImageObject1image, X1, Y1)
e.Graphics.DrawImage(Object2image, X2, Y2)
'... and so on
End Sub
That way transparency and even partial transparency will be rendered properly for all the images. Since the pixels change at runtime, set the Form's DoubleBuffered property to True to prevent flickering. Or use a single PictureBox and its Paint event for everything instead of a Form, because a PictureBox is double buffered anyway.
If you are serious about games development, you may want to move on at some point to using XNA (or DirectX etc.) as Jenner recommends. They will give you much smoother performance for animations. But transparency works just as well using the Paint sub as above (in other words, GDI+) and in my view it's a lot easier to start with.
BB
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|