checking the alpha value of a pixel

JoePro

None Newb
Veteran
Joined
May 29, 2014
Messages
78
Reaction score
17
First Language
English
Primarily Uses
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
 

deathsia

Pegisister
Veteran
Joined
Feb 26, 2014
Messages
648
Reaction score
55
First Language
English
Primarily Uses
I believe what you need is a pixel movement script. a quick google search will provide the links you need for one of these.
 

FenixFyreX

Fire Deity
Veteran
Joined
Mar 1, 2012
Messages
434
Reaction score
310
First Language
English
Primarily Uses
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 :)
 
Last edited by a moderator:

deathsia

Pegisister
Veteran
Joined
Feb 26, 2014
Messages
648
Reaction score
55
First Language
English
Primarily Uses
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


I was simply trying to provide help. So sue me if I was not correct in what they were asking help on.
 

JoePro

None Newb
Veteran
Joined
May 29, 2014
Messages
78
Reaction score
17
First Language
English
Primarily Uses
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.
 

cremnophobia

Veteran
Veteran
Joined
Dec 10, 2013
Messages
216
Reaction score
97
Primarily Uses
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.
 
Last edited by a moderator:

vindaca

CEO of Tales of the Valiant
Veteran
Joined
Dec 11, 2012
Messages
534
Reaction score
75
First Language
English
Primarily Uses
If you are looking for the exact value you should use .to_f unless you dont care.
 
Last edited by a moderator:

JoePro

None Newb
Veteran
Joined
May 29, 2014
Messages
78
Reaction score
17
First Language
English
Primarily Uses
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.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
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"?
 

Napoleon

Veteran
Veteran
Joined
Dec 29, 2012
Messages
869
Reaction score
97
First Language
Dutch
Primarily Uses
bmp = Bitmap.new(1,1)p bmp.get_pixel(0,0).alpha.classreturns a Float. So it already is a float.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,847
Messages
1,016,968
Members
137,561
Latest member
JaCrispy85
Top