0

I I'm trying to make a platform game but im having some problems with making the pictureBoxes (objects like platforms etc) blending in to the background. I've tried setting the background as a parent of the pictureBoxes and using the transparent background setting, but that makes it so that my player cannot intersect with the platforms in the game. The player needs to be able to move around in the background so i cannot make that a child of the background either. Transparencey key seem to make a big hole in my application so i cannot use that either. Bitmap doesnt seem to work unfortunately, i've tried that too:

Bitmap b = new Bitmap(pictureBox2.Image);
        b.MakeTransparent(b.GetPixel(1, 1));
        pictureBox2.Image = b;

I've tried this with both already transparent pictures .Jpeg, .BMP and .PNG and with all white backgrounds, and changing the color like this:

PictureBox2.BackColor = Color.Black;
Bitmap bmp = new Bitmap (pictureBox2.Image);
bmp.MakeTransparent(Color.Black);
pictureBox2.Image = bmp;

Does anyone know how i can solve this ? Thx a million! /Raz

Rasmus
  • 1
  • 2
    I think this is the wrong approach, games with picturebox will be sketchy at best, they are just not designed for moving graphics, try directx or use a dedicated game engine – TheGeneral Feb 17 '19 at 23:03
  • 2
    Only nested controls can support transparency; but usually it is best to DrawImage the graphics and not move controls around.. – TaW Feb 17 '19 at 23:11
  • is there any way i can make nested Controls interact with non-nested controls? – Rasmus Feb 17 '19 at 23:14
  • "... but that makes it so that my player cannot intersect with the platforms in the game." Surely that could be fixed. You'd most likely just need to change your code to deal with different coordinates (because the parent has changed). Or you could give us details on how you determine a "hit". – Idle_Mind Feb 18 '19 at 00:05
  • Another option is to physically change the **SHAPE** of your PictureBox by setting the [Region()](https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.control.region?view=netframework-4.7.2) property of it. You can actually have a non-rectangular control. You'd start with a [GraphicsPath](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.drawing2d.graphicspath?view=netframework-4.7.2) representing the normal rectangle of the PB, then remove all the parts you don't want. Now build a Region from the GP and set it. [An example](https://stackoverflow.com/a/16375699/2330053) – Idle_Mind Feb 18 '19 at 00:09
  • _make nested Controls interact_ ?? Define what interaction you have in mind? Collision detection? You should always have a map of your game world and do test against the map.. – TaW Feb 18 '19 at 09:03
  • yeah i meant like collision detection, decided to use a panel as a background with sky color instead of a picturebox, makes the GIF's and Images way easier to blend in, – Rasmus Feb 19 '19 at 03:01

0 Answers0