Results 1 to 6 of 6

Thread: transparency

  1. #1

    Thread Starter
    Lively Member jayantkumble's Avatar
    Join Date
    Feb 2002
    Posts
    65

    Smile transparency

    hi,
    i am making a screen saver which has some bubbles bouncing here n there. I have an image of the bubble with a black background. My app also runs with a black background. I want the bubbles to be transparent, coz when two image boxes (of bubbles) overlap each other the one behind is hidden by the one in the front. how can i make the black pixels of the image transparent. i'm not using DirectX and if possible i want to do this without using DirectX.
    plz help, thnx in advance.

  2. #2
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Just use BitBlt
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  3. #3
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    Use masking (and bitblt). The sprit (image) should be on a white background, and the mask should be black on white. Then paint the mask to the screen, then and the mask ontop that.
    Involved in: Sentience

  4. #4
    Fanatic Member Mushroom Realm's Avatar
    Join Date
    Mar 2002
    Location
    Murrieta, California
    Posts
    650
    why not just have the bubbles in gif format, u could save it with the transparency.

  5. #5
    Addicted Member jmiller's Avatar
    Join Date
    Jul 2002
    Location
    University of Michigan
    Posts
    238
    The problem with saving them as transparant gifs is that when you use the PaintPicture function it will automatically make any transparancy already in the image black. So using gifs is pointless. If you want to stay away from the API, you can do it with straight VB. Here's how:
    save the bubble picture with a black background. Then make a mask; save the bubble picture where all color pixels are black and all black pixels are white (thus creating a white background). Then, use the Opcode argument in PaintPicture (it's the last parameter). First blit the mask using "vbSrcAnd" in the Opcode. Then, in the exact same coordinates, blit the regular picture using "vbSrcPaint" in the Opcode. This will produce transparancy and only takes two lines of code, whereas the API takes many more (creating dc's and stuff like that). However, this might be too slow for a screensaver, i don't know.
    jmiller

  6. #6
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    You can also use BitBlt without generating the DCs, use the pictureboxes' hDc property... if your game is slow you should try this it's very simple

    VB Code:
    1. 'Put this before all of your form code
    2. Private Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    3.  
    4. 'Now just use it like PaintPicture. The Source DC and Dest DC are the hDc properties of your pictureboxes.
    5. BitBlt ...
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

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