Hi,
In my 2D platformer, I want a particular object to shrink and grow, to appear as if it's breathing/pulsating. I know I can do this by using an animated sprite (that would seem the best/easiest way)... but I'm now intrigued by the fact that I can't figure out how to do it using the scale.x and scale.y properties.
What I'm trying to make it do is this: start at 0.5 scale, increase the scale by .01 until you get to 1.0, then decrease until you get back to 0.5... then repeat ad infinitum.
Here's my best shot so far:
extends Area2D
onready var bling = get_node("bling")
onready var size_min = 0.5
onready var size_max = 1.0
onready var reverse = false
onready var rate = 0.01
func _process(delta):
if reverse:
shrink(rate)
if scale.x < size_max:
reverse = false
else:
grow(rate)
if scale.x > size_min:
reverse = true
func shrink(amount):
$Sprite.scale.x -= amount
$Sprite.scale.y -= amount
func grow(amount):
$Sprite.scale.x += amount
$Sprite.scale.y += amount
In this state, it shrinks down to 0 (why not 0.5?), then starts growing... but never reverses again and just keeps growing and growing forever, rather than reversing.
Thanks!