0 votes

I am new to Godot and game creation in general and I was having trouble figuring out how I would change the size/scale of a sprite when walking further away or closer to screen.

I found something similar here: https://www.youtube.com/watch?v=LbdpkKrVeuU&t=165s

(Even though it is for renpy they both use similar code to python.)

I tried looking online, for the most part, I read something about how you can't change the size of a kinematic body and I should use a node?

I ended up going back and forth and getting really confused by the end of searching.

in Engine by (12 points)

1 Answer

+1 vote

So every thing in the scene is a Node, the "Sprite" is just a type of Node.
For the purpose of what is seen in the video it should be enough to map the position directly to the scale of the same Sprite-Node. Something like this:

extends Sprite

func _process(delta):

    #just to get the sprite to move at all in my test
    position = get_global_mouse_position() 

    #how far down are we on the screen (between 0.0 and 1.0)
    var amount = position.y / get_viewport().size.y

    #apply the scale to this same sprite in both x and y direction
    scale.x = 1 + amount
    scale.y = scale.x
by (923 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 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 webmaster@godotengine.org with your username.