Lachee / raylib-goplus

A newer version of the Go bindings for Raylib
zlib License
76 stars 6 forks source link

Issue Getting Custom Colors to Work #18

Closed ghost closed 4 years ago

ghost commented 4 years ago

Not sure if this is a bug or I am not doing it correctly however apart from the predefined colors raylib also seems to offer the ability to define your own colors using RGBA values.

I am however really struggling to get this to work. If you take a look at the images or text below.

I create the color using the code

// colors green2 = rl.Color{77, 255, 77, 1}

which seems to work fine however Visual Studio Code gives me a WARNING (not error)

github.com/lachee/raylib-goplus/raylib.Color composite literal uses unkeyed fields

However it allows me to compile the code the problem is that though the program runs the color is blank and does not display, what is supposed to be green is just blank with no color at all.

If you have any help/advice as to how to create/use custom colors it would be really appreciated.

Nicholas

Annotation 2020-08-18 081729 2

Lachee commented 4 years ago

Hello, That is a REALL dumb linter error with go. I have had this on several other projects and can be mostly ignored. There are solutions to disable it, but i am not sure what they are since it was an issue long ago.

The basic issue is that Go thinks you should be using the constructor instead of defining it as a literal (the Color{ ... } part). What you should be using isntead is rl.NewColor(77, 255, 77, 1)

ghost commented 4 years ago

Hi, thanks for getting back to me so quickly. That is still not working, the color is still blank, not sure if I am doing something wrong, the code compiles and runs perfectly with no errors or warnings however the color is still not displaying, I tried 2 versions of code see below and neither works

green1 := rl.NewColor(77, 255, 77, 1) for a := 0; a < playerhp; a++ { rl.DrawRectangle(51+xchange, monh-59, 3, 28, rl.Color(green1)) xchange += 3 }

as well as this one

green1 := rl.NewColor(77, 255, 77, 1) for a := 0; a < playerhp; a++ { rl.DrawRectangle(51+xchange, monh-59, 3, 28, green1) xchange += 3 }

Whilst they both compile and run neither of them displays the color. This might also be an issue with Raylib itself I am not sure, perhaps you are correct and there is an underlying error in the Raylib library, which is another possibility why it is not working,

Annotation 2020-08-18 102434 2

ghost commented 4 years ago

If you have any ideas as to how to get it working it would be great.

Lachee commented 4 years ago

well you have set both their alpha to 1. Try setting it to 255

ghost commented 4 years ago

Thanks, that worked just changed to 255 and it works perfectly, appreciate it. I am assuming that Alpha is the fade so 1 is invisible and 255 is full color is that correct?

Lachee commented 4 years ago

Yup, well actually 0 will be fully transparent but that is correct.