Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | IHate |
I have a function where I create a RectTexture and set its texture and scale like this:
func create_hover_preview(item):
hover_preview = TextureRect.new()
add_child(hover_preview)
yield(get_tree(),"idle_frame")
hover_preview.texture = item.texture
hover_preview.rect_scale = Vector2(2,2)
The texture is applied to the node even without the yield but the node is never scaled
but something like this works:
func create_hover_preview(inv_grid:Object, idx:int, item:Item):
hover_preview = TextureRect.new()
add_child(hover_preview)
hover_preview.texture = item.texture
rescale(hover_preview)
func rescale(hover_preview):
yield(get_tree(),"idle_frame")
hover_preview.rect_scale = Vector2(4,4)
Shouldn’t both of these work exactly the same? what am I missing?
No idea really, though I do notice that in the first example, you’re both assigning the texture and scaling it after yielding for idle_frame. In the second example, you’re assigning the texture before the yield and then scaling it after.
With that in mind, I wonder if moving the texture assignment to before the yield in the first example makes any difference?
jgodfrey | 2020-10-27 21:07
It actually does make a different and putting yield just before setting the scaling works as I intended but I don’t understand why. Don’t the rest of the lines in the function wait for the yield? Maybe it can’t set the scaling before the texture is drawn? But you can set the scale of a RectTexture even if it doesn’t have a texture…
IHate | 2020-10-27 21:30