Hi to everyone ;)
I was wondering: is there a way to set the transparency of an image? I'm trying to have a sort of glow effect, but with no transparency that's pretty hard :S
Draw this image using color with lower alpha value, like 0x80ffffff
cool, this seems to work :P
is there a way i can insert a variable inside the alpha value? i mean: this isn't working, but if i had the possibility to write something like this:
@immagini_logo.draw(0, 0, 0, factor_x=1, factor_y=1, color=0x(ff-$n)ffffff)
with $n floating between 00 and ff, i could have my glowing image. But this code just doesn't seem to work :\
use the Color class instead of a fixnum
uhm. sorry but, as you can see, I am definitely a noob. How can I use a class to modify the color of the image? you mean using Gosu::Color in someway?
@immagini_logo.draw(0, 0, 0, 1, 1, Color.new(alpha , red , green , blue))
And you don't need to write 'factor_x=' or 'color=' each time.
@immagini_logo.draw(0, 0, 0, 1, 1, ((0xFF - $n) << 24) + 0xFFFFFF)
(Or use the the Color class
like Dahrkael said).
-1 for being the sort of hack I'd resort to. :D
I only did it to show how close his code was to working. He's obviously a newbie (no offense, Italian reaper dude) and I knew there would be other people spoiling him by coding it for him "the right way". This way, I thought he might at least learn something on his own, even if it's not directly "properly" applicable here...
Hopefully the jocular nature of my comment came through! I have done it that way and probably would again. :D
no offense, I surely am a newbie ;)
(i do these things for hobby, i never had some serious programming course... i do what i can XD)
ok, this works, but i can't understand why.
what's that << 24 ? :S
It means "shift a number 24 bits to the left". It's shorthand for "multiply by 16777216". It seems to be a bit beyond your skill level at this point, but if you keep learning about programming you'll eventually get to binary math and it'll make sense. Just do it the "right" way using Gosu::Color.
It's also worth a note that you probably shouldn't be using the $ sigil (as in $n), because that indicates a global variable. Just use a bare name for local variables.
You will encounter strange bugs later using global variables like that if you use the same name in more than one place. C:
uhm. but if i use a local variable, then i can use it in an other method?
for example, in this case, now we have:
$glow_logo = 0
$glow_logo_boolean = false
if $menu == true then
if $glow_logo_boolean == false then
$glow_logo = $glow_logo + 2
if $glow_logo == 200 then
$glow_logo_boolean = true
$glow_logo = $glow_logo - 2
if $glow_logo == 0 then
$glow_logo_boolean = false
if ($menu == true) then
@immagini_logo.draw(0, 0, 0, factor_x=1, factor_y=1, ((0xFF - $glow_logo) << 24) + 0xFFFFFF)
I just tried to change $glow_logo_boolean in a local variable, but it doesn't work.
Well, for variables that need to be shared across methods, use an instance variable. They shouldn't need to be accessible outside of your object.
As for fading in and out, let me see if I can get the math right this time. I wrote an equation that was wrong and kept getting the corrections wrong a while ago because I was on a tablet and couldn't test it!
There we go.
0.5 + Math.sin(Math::PI * Gosu.milliseconds / 1000.0) / 2 should give you a float in the range 0 – 1 inclusive, with a period of one second. If you want toit to go faster or slower, change 1000 to something else—it's basically the period in milliseconds.
alpha = (128 + 128 * Math.sin(Math::PI * Gosu.milliseconds / 1000.0)).floor
@immagini_logo.draw 0, 0, 0, 1, 1, Gosu::Color.argb(alpha, 255, 255, 255)
By il mietitore
it works but i can't understand what the heck is that >.<
what is PI? and that .floor? O___O
(thanks a lot =D )
PI is a math constant. You should know it from school.
.floor removes decimal, like (1.25).floor = 1
ah, the π!
what i'm trying to understand is: why this equation gives a different result at every refresh? i mean, there are no variables that changes each time... i suppose it's related to that Gosu.milliseconds, because all the other things are fixed >.< what is that Gosu.milliseconds, anyway?
The current time in milliseconds. The rdoc is ugly right now, but you will still be able to find all that here: http://libgosu.org/rdoc
So here it is, now it's all clear.
Well thanks a lot to everyone in here ;) i suppose i'll be back soon, i'll surely find some other curious problem to fight with.
i tested the snippet and it crashes after some seconds.
argb': Wrong arguments for overloaded method 'Color.argb'. (ArgumentError)
Possible C/C++ prototypes are:
Gosu::Color Color.argb(Gosu::Color const *self)
Gosu::Color Color.argb(Gosu::Color::Channel a, Gosu::Color::Channel r, Gosu::Color::Channel g, Gosu::Color::Channel b)
Gosu::Color Color.argb(std::tr1::uint32_t argb)
from test.rb:18:in `<main>'
>Exit code: 1
The trick is to use
127.5 + 127.5 * ...:)
Oops! Wow, that didn't happen for me even after many, many iterations. I had numerous previous versions that did. :D
@jlnr Can we get a constructor that takes normalized floats? I'm much more comfortable with those. C:
I thought about overloading it, but it would be confusing if passing 1.0 and 1 would make a difference. I could add a _f variant for everything on Color, but I am not sure about that.
It may be a bit clearer if you work with normalized floats and then do *255 in the end, though. Now if Color.argb only called .to_i on its arguments...sigh.
Color now (=in the next release) truncates and wraps all values into 0..255 automatically. That was a painless fix at least. :)
This is a good change. :D
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill