• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

HTML5 draw_getpixel with html5?

duran can

Member
Hi,
draw_getpixel(mouse_x,mouse_y); is working very well on windows but not working on html5, how can i use?
1611818951531.png

*using v2.3.1.542 on steam

anyting?
 

matharoo

manualman
GameMaker Dev.
What issue are you getting? Is it returning the wrong color or is it returning nothing?

Can you show your code?
 

duran can

Member
What issue are you getting? Is it returning the wrong color or is it returning nothing?

Can you show your code?
code is simply getting pixel, no errors. if webgl is not activated getting 0 value, if webgl is activated getting wrong color value (like on image)
GML:
draw_set_color(draw_getpixel(mouse_x,mouse_y));
draw_text(mouse_x,mouse_y-32,draw_getpixel(mouse_x,mouse_y));
draw_set_color(c_white);
 

matharoo

manualman
GameMaker Dev.
What if you used device_mouse_x or device_mouse_x_to_gui instead of mouse_x? There's also device_mouse_raw_x so you can try that.
 

duran can

Member
What if you used device_mouse_x or device_mouse_x_to_gui instead of mouse_x? There's also device_mouse_raw_x so you can try that.
still not working did you on html5 try? i dont think this problem about mouse coordinates.. couz of writing draw_text on same coordinate.


getting wrong color on this code:
GML:
var xx=device_mouse_x_to_gui(0);
var yy=device_mouse_y_to_gui(0);
draw_set_color(draw_getpixel(xx,yy));
draw_text(xx,yy-32,draw_getpixel(xx,yy));
draw_set_color(c_white);
and this code:
GML:
var xx=device_mouse_raw_x(0);
var yy=device_mouse_raw_y(0);
draw_set_color(draw_getpixel(xx,yy));
draw_text(xx,yy-32,draw_getpixel(xx,yy));
draw_set_color(c_white);
 

Padouk

Member
AHoy @duran can

I remember a similar issue couple of years ago in one of my project. I wasn't using GMS at that time so this answer is a shot in the dark
Quoting: https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/readPixels
xA GLint specifying the first horizontal pixel that is read from the lower left corner of a rectangular block of pixels.
I know this is silly, but try using (browser_height - yy) or something similar to inverse it top down / bottom up
 
Top