Question

enter image description here

Take a look at the image above. I'm creating a (recreation) of a tile-based game. In my other sprites, I've simply been placing the terrain squares into the grid, they are solid so there was no problems. The problem here is that, if I use this character now, it tries to show the pink behind him (He is 16x16).

I'm using System.Graphics to display the items (and cutting them out when using graphics.DrawImage()). Is there any way I can have it ignore specific colors and make them transparent?

I'm using VB.net so all .net answers are acceptable.

For a point in the comments (or and extra point in your answer), what is the method called where you use a pink grid to contain all your sprites?

Was it helpful?

Solution

You should probably convert your image to a PNG and make the background transparent. If not, you can just convert the bitmap:

Public Class Form1
  Private bmp As Bitmap

  Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
    bmp = New Bitmap(bitmapFileName)
    bmp.MakeTransparent(Color.FromArgb(255, 0, 220))
  End Sub

  Private Sub Form1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint
    e.Graphics.DrawImage(bmp, New Point(32, 32))
  End Sub
End Class
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top