tmx icon indicating copy to clipboard operation
tmx copied to clipboard

[docs] wrong usage of color in raylib example.

Open Ghibranalj opened this issue 3 years ago • 1 comments

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});

Ghibranalj avatar May 10 '22 19:05 Ghibranalj

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

baylej avatar May 10 '22 20:05 baylej