checking the alpha value of a pixel

● ARCHIVED · READ-ONLY
Started by JoePro 10 posts View original ↗
  1. Hello everyone,

    How can I check JUST the alpha value of a pixel.

    I'm am using this as of right now(I know it doesn't work)

    Code:
    @enemy_bitmap.bitmap.get_pixel(x, y).to_a[4] >= 1
  2. I believe what you need is a pixel movement script. a quick google search will provide the links you need for one of these.
  3. In what way did the OP insinuate that they wanted or needed pixel movement? Break down the word assume, and you'll find a wonderful life lesson. Lol :p

    @JoePro, if you'll press F1, the help file will come up, and you can click the 3rd tab, Search. Search for Color, and you'll see that you can simply call the alpha method, which returns the color's alpha value:

    Code:
    color = bitmap.get_pixel(x, y)return color.alpha
    Hope this helps :)
  4. FenixFyreX said:
    In what way did the OP insinuate that they wanted or needed pixel movement? Break down the word assume, and you'll find a wonderful life lesson. Lol :p

    mlfw8177_medium.png

    I was simply trying to provide help. So sue me if I was not correct in what they were asking help on.
  5. Thank you FenixFyreX for clarifying that ever so gently.

    This site has a lot of scan readers on it. Someone did that to my last post too. Help is only Help if you Help. How can you help if you don't take the time to read.

    On with the topic.

    color = bitmap.get_pixel(x, y)return color.alpha

    Thanks for the response but as you will notice in my first post that is the method I am using. I need to know how to access or check just the alpha value from that.

    it returns a value of (red, green, blue, alpha) or whatever. However I do not know how to access just the alpha value from this, I don't care about the other values.

    BTW i know I am new to the site but FYI I am in no way new to RM or the RGSS help file. Thank you anyways for the suggestions as I am sure it will be of use to someone else that might read this.

    This is more of a "General Ruby" question I believe. I have never had something returned inside of () before and do not know how to extract from it.
  6. Bitmap#get_pixel returns an instance of Color. The Color class has 4 attributes: red, green, blue, and alpha. You can get the value (between -255.0 and 255.0, but practically usually between 0.0 and 255.0) of one by calling the identically named instance method. It would have been more helpful (not saying it wasn't, it was!), if FenixFyreX had “corrected” your code instead of giving an (incomplete) example:
    Code:
    @enemy_bitmap.bitmap.get_pixel(x, y).alpha >= 1
    By the way, checking every pixel of an image may be very slow.
  7. If you are looking for the exact value you should use .to_f unless you dont care.
  8. Thank you all very much. I didn't catch the

    return color.alphaThank you Cremnophobia for pointing that out. Thank you Vindaca, I knew about that but it does help.

    Thanks again all, mod can close this post.
  9. vindaca said:
    If you are looking for the exact value you should use .to_f unless you dont care.
    If the value you're given is an integer, how does converting it to float give you an "exact value"?
  10. bmp = Bitmap.new(1,1)p bmp.get_pixel(0,0).alpha.classreturns a Float. So it already is a float.