Results 1 to 3 of 3

Thread: True transparent pictureboxes?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2012
    Posts
    142

    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

  2. #2
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    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.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  3. #3
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: True transparent pictureboxes?

    Quote Originally Posted by ikdekker View Post
    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
  •  



Click Here to Expand Forum to Full Width