0 votes

How to get pixel color under cursor?
I saw similar question as mine but those answers are in the gdscript when I programming in c#

asked Nov 10, 2019 in Projects by daniel500013 (54 points)
edited Nov 10, 2019 by daniel500013

1 Answer

+2 votes
Best answer

I don't use the Mono version of Godot but I guess it would be just similar to GDScript. https://docs.godotengine.org/en/3.1/getting_started/scripting/c_sharp/c_sharp_differences.html#general-differences

So something like: (inside a node)

GetViewport().GetTexture().GetData().GetPixel(x,y);

x,y should be retrievable from the mouse event.
https://docs.godotengine.org/en/3.1/tutorials/inputs/mouse_and_input_coordinates.html

If you intend to work with/change many pixels often then it might be advisable to use a screen shader. (Depends on your specific use case.)

answered Nov 11, 2019 by wombatstampede (2,879 points)
selected Nov 11, 2019 by daniel500013
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.