• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code draw_getpixel doesn't work... maybe?

A

axl_gmd

Guest
I have a little issue here.

I have a room with an asset layer with a sprite. I'd love to analyze the color of every single pixel of that sprite. So I create and object and in the draw event I let two for loops go like that:

Code:
for (i=0;i<room_width;i++) {
     for(j=0;j<room_height;j++) {
          var col = draw_getpixel(i,j);
          if (col == $FFFFFF) {
               //do some stuff
          } else if (col == $FF0000) {
                // do other stuff
          }
              // etc
     }
}
But the code doesn't work at all. By debugging, the variable "col" doesn't change value, it is always 0.
What am I getting wrong?
Thanks in advance, I hope you understood what I said!
 
Last edited by a moderator:
Z

ZaOniRinku

Guest
Try to increment the x position until the end of the sprite, then putting the x to 0, then incrementing the y, then incrementing the x position until the end of the sprite, etc. You should also try to keep all the values somewhere (like in a file), it will be easier to find a solution.

Edit : Error
 
Last edited by a moderator:
A

axl_gmd

Guest
I'm sorry, I don't think I understood... do I have to switch i and j so to register colours line by line and not coloumn by coloumn?
Because unfortunately I already did that and it doesn't work.
Also, I use "show_debug_message(string(col))" also and the values are all zero.
Isn't maybe a bug of the engine..?
 
A

axl_gmd

Guest
That's weird... I don't see why your code is failing... According to the documentation (https://docs.yoyogames.com/source/dadiospice/002_reference/drawing/colour and blending/draw_getpixel.html), the results "will depend on the event in which the function is called". Maybe this is where the problem come ?
Yeah I read it too and the documentation hasn't helped at all... I put the event in the draw event first, and then in the create.
EDIT: I tried to put it on a "Key Press" event and it seems that it loops infinitely. I'll restart from there maybe
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
What depth is the instance doing the checking at? It may be that the draw for that instance is being called before the rest of the instances and you are simply getting the backbuffer colour returned... Try using the Draw END event. You could also use surface_getpixel() on the application surface rather draw_getpixel().
 

gnysek

Member
Wouldn't this function check against what's send to screen (so buffer or application_surface) not real x,y in room? I mean if you're using views, draw_getpixel(0,0) will return top-left corner of screen not 0,0 in room, as it's may be outside view? Maybe here is problem.
 

Mike

nobody important
GMC Elder
Thats just as slow... reading data back from the GPU is always slow no matter how your doing it. Only if you delay reading by several frames will it not hurt as much.
 
A

axl_gmd

Guest
I finally solved by inserting that piece of code an alarm event that goes 1 step after the room is initialized with the sprite and all.
It really seems that draw_getpixel is that slow.
I also tried to put it in the Draw END event as suggested by Nocturne but it doesn't seem to work, very strange.
 
Top