baylej / tmx

C tmx map loader
http://libtmx.rtfd.io/
BSD 2-Clause "Simplified" License
235 stars 53 forks source link

[docs] wrong usage of color in raylib example. #68

Open Ghibranalj opened 2 years ago

Ghibranalj commented 2 years ago

in this page's example for raylib the function draw_title() uses float for color.Raylib's color uses char. also the range for color in raylib is (i think) 0 - 255, where as here the value of opacity here is 0-1.

void draw_tile(void *image, unsigned int sx, unsigned int sy, unsigned int sw, unsigned int sh,
               unsigned int dx, unsigned int dy, float opacity, unsigned int flags) {

 // here the opacity has the value between 0-1, raylibs color is 0-255
  DrawTextureRec((Texture2D*)image, (Rectangle) {sx, sy, sw, sh}, (Vector2) {dx, dy}, (Color) {opacity, opacity, opacity, opacity});
}

maybe something like this is the solution, idk if there is a better one.

    .....
    float norm_opacity = opacity * 255;
    char color = (char)norm_opacity;
    DrawTextureRec(texture, (Rectangle){sx, sy, sw, sh}, (Vector2){dx, dy},
                   (Color){color, color, color, color});
baylej commented 2 years ago

Hi, Indeed you're right, see: https://github.com/baylej/tmx/blob/master/examples/raylib/raylib.c#L73