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.

adding a color method in Bitmap

Hi,

Sorry for my quite bad English, but I am French...  :wink:

I would like to add a color method in the Bitmap class, like the Sprite's.
(Naturally, I can't and I don't want to use the color management of the Sprite class)
eg:
bmp.color=Color.new(152,25,125,55)

Code:
class Bitmap
  def color=(col)
    bmp=Bitmap.new(self.width,self.height) 
    bmp.fill_rect(0,0,self.width,self.height,col)
    self.stretch_blt(Rect.new(0,0,self.width,self.height), bmp, bmp.rect) 
    bmp.dispose
  end
end

but the transparent color management in the background is deleted.
Should I use a recolor pixel by pixel?
Has someone an answer to my question ?

thanks, :thumb:

berka
 

e

Sponsor

I'm not sure I understand your question, but you're in luck(!): my first language is French.
So just go ahead and post it in French.

So basically you've added this method (which, from what I gather, should work), but you're losing something?

As far as I know, there is no such thing as a "background" in a bitmap; a background itself is a Bitmap object.
 
thanks for reply,
In fact, there is no background color with a bitmap.

I would like to add a kind of a colored layer to the bitmap object.
I tried to merge a second colored bmp.fill_rect with the original, but the transparent color was now colored... :crazy:

and what about the bitmap's taint method ? it retrieves another bitmap or self...
 
Should I use a recolor pixel by pixel?
If you want to add a color layer to the bitmap, then yes, you'll have to recolor pixel by pixel.
Why? Simply because you can't have "layers" in a bitmap. If you draw something into a bitmap, and then want to aff let's say a transparent red rectangle over the text, then the text will be kinda erased and the rect will take the place.

Doing a pixel by pixel recolor would be quite heavy for the system. I don't recomend doing it.
I personally would use a sprite to do that. Is a lot more easier!

Hope it helps.
-Dargor
 
thanks...
but I can't use a Sprite, because I need a bitmap to save as a png file...
I change the color bitmap once per second, therefore, the process may be slow and heavy... It doesn't matter !
Using a pixel process, how could I manage the alpha color, and transparency, since rmvx keeps the file's background color but doesn't display it.

berka
 

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