Transparent images?

Just starting out? Need help? Post your questions and find answers here.
Fleath//
User
User
Posts: 47
Joined: Sun Feb 13, 2005 11:37 am
Location: Australia
Contact:

Transparent images?

Post by Fleath// »

I only seem to pop up when I have a question, so here I am once again. After months playing around with my map engine and remaking it over and over, I've just decided to make a general-purpose engine for all my games. So far it's all working perfectly on the back-end side of things. My problem is with the map drawing program to manage it.

I've made mapping programs out of sprites alone (so part of each tile can be transparent), but it's amazing irritating to get off the ground. And this one is quite a bit more complicated than my earlier attempts, so this time I'll be using forms and images.

So my questions are:
How do you make a certain colour of an image transparent? I know you can use .PNG files which have a channel for it, but I want to have it done inside the program without too much mucking around.
I also know you can draw each pixel one by one, and just skip the transparent colours, but I've tried this and it takes quite a long time to draw a map of 16x16 tiles, and that was all I could find when I searched the forum...
If I can get that to work, I'd also need to be able to cut each tile from the sheet of tiles and draw them individually on the map too.

Basically I need a way to use the transparent sprite drawing command and the sprite cutting command, but with images.

Code: Select all

crush()
kill()
destroy()
Image
Add to PB logo to your game today.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Code: Select all

Procedure DrawTransparentImage(DC.l,ImageID.l,x.l,y.l,TransparentColor.l)
  Protected ImageList.l, BM.BITMAP
  GetObject_(ImageID,SizeOf(BITMAP),BM.BITMAP)
  ImageID = CopyImage_(ImageID,#IMAGE_BITMAP,BM\bmWidth,BM\bmHeight,0)
  ImageList = ImageList_Create_(BM\bmWidth,BM\bmHeight,#ILC_COLORDDB|#ILC_MASK,1,0)
  ImageList_AddMasked_(ImageList,ImageID,TransparentColor)
  ImageList_Draw_(ImageList,0,DC,x,y,#ILD_TRANSPARENT)
  ImageList_Destroy_(ImageList)
  DeleteObject_(ImageID)
EndProcedure

Code: Select all

DC = StartDrawing(WindowOutput())
  GrabImage(#img,#img,0,0,0,0) ;resize image (just like the sprite cuttin
  DrawTransparentImage(DC,ImageID(#img),0,0,#Black)
StopDrawing()
I guess you'll figure it out now! :wink:
Fleath//
User
User
Posts: 47
Joined: Sun Feb 13, 2005 11:37 am
Location: Australia
Contact:

Post by Fleath// »

You sir have saved my butt, works perfectly thanks!

Code: Select all

crush()
kill()
destroy()
Image
Add to PB logo to your game today.
Post Reply