By Tekk
Date 2010-01-16 07:18
alright so I have an array of colors: @col = ["255,0,0", "0,255,0", "0,0,255", "0,255,255","255,20,147"]
and I want to actually use them to color my sprite: image.draw(@x - image.width / 2, @y - image.height / 2,ZOrder::Stars, 1, 1, @col[rand(@col.length)].to_i, :additive)
the problem is that ruby wants an int for my colors, and .to_i makes the images invisible, can anyone help?
By lol_o2
Date 2010-01-16 07:34
Edited 2010-01-16 17:56
You made these colors as strings? They should be written as Color.new or hex. Try this array: @col = [0xffff0000, 0xff00ff00, 0xff0000ff, 0xff00ffff,0xffff1493]
By jlnr (dev)
Date 2010-01-16 09:34
You can use an Array full of Gosu::Color.new(a,r,g,b) calls if you want to specify each components as a decimal number :)
And if the above suggestions aren't an option (if you're reading those strings from a file or network stream or something) then you could transform them like so:
@actual_colors = your_color_strings.map do |triplet|
Gosu::Color.new 255, *triplet.split(',').map { |n| n.to_i }
end
Do this once, obviously. If you do the transformation every frame then it's going to be slow. I don't recommend doing it like this if you can take one of the other solutions because it unnecessarily complicates your code.
Loading...