Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[Rubygame]Making transparent surfaces

I'm developing a map editing application, and all is going well, except for blitting transparent surfaces from scratch to the screen.
If i blit a .png with transparency, it merges them fine - the sprite on the background.
But if I blit a surface (Surface.new([width;height])), it leaves a black box, rather than the transparency.

How to I get the alpha channels to merge correctly from Surfaces made from scratch?
 
This is from a different project, but the issue is the same.
The reason I was sending the text to another surface was to apply an outline - I've removed the outline code for now.
Pretty much:
Ruby:
  def draw_text(font,string,color)

    size = @font[font].size_text(string)

    text2 = @font[font].render(string,true,color)

    surface = Surface.new [text2.w,text2.h],0,[HWSURFACE,SRCALPHA]

    surface.to_display_alpha

    text2.blit(surface,[0,0])

    return surface

  end

 

# other stuff . .  .

    @text  = []

    @text[0] = draw_text('ubuntu,16','Armour',[255,255,255])

    @text_rect = []

    @text_rect[0] = Rect.new(16,20,@text[0].make_rect.w,@text[0].make_rect.h)

 

#moar stuff . . .

 

    @text[0].blit($screen,@text_rect[0]) # within the draw method

 
 
You need to assign a surface to surface.to_display_alpha and blit that, you should be able to write:
surface = surface.to_display_alpha
and it should work, the reason is that it's not a self-modifying function it has a return value of a new surface.
 
ZenVirZan":x7uvax8p said:
Its merging now, thank you :D
Its a pity they don't make it more noticeable in the documentation - It's such a simple mistake.
And now this is when I shock you by revealing I've never coded in Ruby before and that I've never used RubyGame before.
 
Xilef":2x3gr8hj said:
ZenVirZan":2x3gr8hj said:
Its merging now, thank you :D
Its a pity they don't make it more noticeable in the documentation - It's such a simple mistake.
And now this is when I shock you by revealing I've never coded in Ruby before and that I've never used RubyGame before.

Oh wow. :blank:
I am shocked D:

EDIT: New issue.
3 surfaces.
a = Loaded from png with transparency
b = Scratch (has been converted)
c = Scratch (has been converted)
Blitting surfaces a => screen, b => screen and c => screen works
Blitting surfaces a => b => screen and a => c => screen works
But blitting a => b => c => screen doesnt.
If two surfaces have to_display_alpha set, it doesn't show the PNG image blitted onto it.
 
ZenVirZan":185dy8wg said:
3 surfaces.
a = Loaded from png with transparency
b = Scratch (has been converted)
c = Scratch (has been converted)
Blitting surfaces a => screen, b => screen and c => screen works
Blitting surfaces a => b => screen and a => c => screen works
But blitting a => b => c => screen doesnt.
If two surfaces have to_display_alpha set, it doesn't show the PNG image blitted onto it.
Could you tell me the dimensions of these surfaces and the screen you're blitting to?
 
surface 'a' is the tileset png file, alpha included.
surface 'b' is a 32x32 tile, blitted to from the tileset image.
surface 'c' is a 1024x800 layer, and has the surface 'a's blitted to it to make the map. (#to_display_alpha is applied)
'screen' is a 1280x800 Screen instance.

If I put #to_display_alpha on surface b, it doesn't show up.
If I omit it, it does show, but the alpha is replaced with black.
 
Why are you using surface B at all? You should use clipping to blit a 32x32 section of A straight to C and do any modifications there to save processing speed.
You can do that with the third blit parameter which is a rectangle, instead of having only the x and y position you can add in the width and height of the blit, using surfaces to clip is very inefficient as you're copying entire blocks of ram to a fresh set of memory twice.

$a.blit($c,[destinationX,destinationY],[tileX,tileY,32,32])
 
I have a grid class, which has a method #get_tile(id)
It returns a 32x32 tile surface from the tileset, depending on the id.
It already uses the source rect function of #blit to get the tile onto surface b to begin with.
Even though b may not be required, i'd still like to know for future reference.
 
I don't think I can help any further then, I generally don't blit through more than two surfaces, it's probably a problem with preserving the alpha channel (Perhaps it's being overwritten when blitting from B to C?), it would be a Rubygame specific bug (And from looking at the git page, it's full of them)
 
I believe some of you must be a football fans,and you may heard about the PS3/XBOX360/pc video games called FIFA, the latest game is FIFA 14, I'm really enjoy it with the help of guild wars 2 gold meanwhile,I want to share theis imofrmation to you ,my friend, if you administor thik this massage annoied you, please forgive me, PLS keep this massage for about 2 or 3 days, TKS.:)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top