Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | monotonehell | |
Old Version | Published before Godot 3 was released. |
Hello! My first time playing with Godot & GDScript, so everything is new to me. I’m trying to get colour pixel data from a picture with the intention of using pictures to generate tilemap worlds. But I’ve stumbled at the second hurdle…
Testing the idea I did this:
var image = load("res://assets/HeightMap1024x1024.png")
var map = get_node("/root/home/MapPreview")
map.set_texture(image)
print(map.get_texture().get_data().get_pixel(100,100).to_html(false))
“MapPreview” is a texture frame control. The above code is triggered by pressing a button.
The picture appears in the frame, no problem. But the print() output, no matter where I target in the picture is always “000000” (The pixel at 100,100 is dark blue.)
Same happens in stable and a nightly build.
In 3.0 the debugger gives the following “Condition ’ !ptr ’ is true. returned: Color()” which I don’t understand.
What am I missing?
**UPDATE: I installed 2.1.4 and it works there. Still not working in 3.0 (a 2 day old nightly build from Service End for Bintray, JCenter, GoCenter, and ChartCenter | JFrog) . **
Also note 3.0 has changed TextureFrame to TextureRect
Promoted to a bug report: get.pixel always returns zero (black) · Issue #12245 · godotengine/godot · GitHub
The below code appears to work in 2.1.4, but gives the same error as you received in 3.0. I’m going to venture a guess get_data
or get_pixel
is broken in 3.0 for the time being; you may have to temporarily work around it or wait it out.
extends TextureFrame
func _ready():
set_texture(load("res://icon.png"))
var tex = get_texture()
var size = tex.get_size()
randomize()
var x = randi() % int(size.x)
var y = randi() % int(size.y)
print(Vector2(x,y), ": ", tex.get_data().get_pixel(x,y).to_html(false))
Unless someone more knowledgeable than me has an answer…? (Edit: See Tapio Pyrhönen’s answer.)
aozasori | 2017-10-19 07:36
You seem to be correct that it’s a bug in 3.0. I just reinstalled 2.1.4 and it does work there. But does not work in 3.0.
I think I’m going to turn this into a bug report on GitHub, using your example code.
Thanks for your help.
monotonehell | 2017-10-20 00:05