Image.fill always gives a white texture - Solved -
Asked Answered
N

6

0

-- SOLVED --
The last flag in Image.create needed to be 4 so that the channel for colors exists.

I'm working on a pixel based world map for my game. To make it, I need to create an image and set it to the texture of a textureRect. To start it, I was going to use the Image.fill() function to set a base blue background. But the only colors I can get are blank white or black, no matter the color I set it to fill.

Here's my code

extends Control

@onready var texture = $TextureRect

func _ready():
	var map = Image.create(50, 50, false, 0)
	map.fill(Color.CORNFLOWER_BLUE)
	texture.texture.set_image(map)

I've set the color to be the RGBA value for cornflower blue, other blues, and to Color(0, 0, 0, 1), and the only one that made it anything other then white was Color(0, 0, 0, 1), or pure black.

To be clear, texture is a TextureRect with the texture set to be a blank, default ImageRect.

Thanks for the help!

Number answered 5/1 at 0:33 Comment(0)
E
0

Number texture.texture.set_image(map)

Try this instead:
texture.texture = ImageTexture.create_from_image(map)

Eldridge answered 5/1 at 1:35 Comment(0)
N
0

Eldridge no change, thanks for the try

Number answered 5/1 at 1:36 Comment(0)
E
0

I may experiment with it. I've created polygonal shapes with solid colors in code, and that works correctly. However, I'm using Polygon2D, not TextureRect.

Eldridge answered 5/1 at 1:42 Comment(0)
E
0

Actually, if your objective is to have a solid color rectangle, you could use a ColorRect.

Eldridge answered 5/1 at 1:51 Comment(0)
N
0

Eldridge Okay. Thank you for your help!

It needs to be an image because its a pixel map, so ColorRect won't work

Number answered 5/1 at 1:51 Comment(0)
N
0

Eldridge I figured it out. I needed to change the last flag when making the Image object, as that controls what channels the pixels in the image can have. Thanks for the help!

Number answered 5/1 at 1:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.