The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+3 votes

So I solved one of my problems using a TextureRect but it doesn't seem to scale at all.

var s = Vector2()
s.x = 0.5
s.y = 0.5

This seems to output the .5 .5 vector2 I have but the image doesn't scale at all. I'm trying to shrink it to about half the image size. What am I doing wrong?

in Engine by (60 points)
edited by

have you tried changing the Stretch Mode property of the TextureRect?

yes I can't seem to figure it out. I tried going through them all with no luck but there may have been other factors so I'm not sure how to do it right if that's the solution.

I've tried various forms of this code to no avail. when I turn on expand the images disapear.

    cardn[cardcount].rect_scale = s
    #cardn[cardcount].scale = .5

setting scale in the GUI of godot works but I'm trying to do this with code....

Here's my full thought process. I've deleted Hboxcontainer and readded it to the scene so its in defaults. strech mode alone doesn't seem to have any effect 0 -7 it all displays the pictures but not scaled down and when on 3 or 4 with expand it writes over the same spot and negates hboxcontainer. the other strech mode options with expand make the images disapear. getscale returns that the rectscale value is changing but my images don't shrink.

    cardn[cardcount].set_name("card" + String(cardcount))
    cardn[cardcount].texture = actual[showcard] 


    #cardn[cardcount].rect_scale = s
    #cardn[cardcount].scale = .5



3 Answers

+2 votes

You probably want to set the rect_scale property. So, assuming cardn is an array of TextureRect, something like:

cardn[cardcount].rect_scale = Vector2(2, 2)
by (22,674 points)

I've tried this it doesn't seem to shrink my images when a variable definted as Vector2 is .5 .5

It definitely works here. It might have to do with how it's anchored, or how the Expand and Stretch Mode properties are defined in the inspector...

Its a child of an hboxcontainer. setting strech mode to 3 or 4 makes the image show with expand on but it writes over itself and doesn't arrange in the hboxcontainer and doesn't scale.

also I don't have access to the inspector I'm trying to do this with code....

+4 votes

I was able to get it to do what I want with this function. Not sure why I can't do it with scaling though.

func get_resized_texture(t: Texture, width: int = 0, height: int = 0):
    var image = t.get_data()
    if width > 0 && height > 0:
        image.resize(width, height)
    var itex =
    return itex
by (60 points)

Tnx! Realy working!

+4 votes

I just commented on this over here , but for better visibility will post it here as well:

var s = Vector2(2.0, 2.0)
cardn[cardcount].expand = true
cardn[cardcount].rect_min_size = cardn[cardcount].rect_size * s

This will only work of course, if rect_size is set to the size of the texture. Which will happen automatically when you add a texture in the inspector, but has to be done manually if you're doing that from within GDscript. I assume this won't be an issue, given that your designing a card game and I expect all cards to have a uniform size.

by (10,634 points)
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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.