Cant get index height on base vector2

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By kieranbramley

unsure on what im doing wrong. help would be apprieciated

extends Sprite

export var velocity = Vector2()

func _ready():
set_process(true)
pass

func _process(delta):
translate(velocity * delta)

if get_position().y >= get_viewport_rect().size.height:
	set_position(Vector2(0, -200))
pass
:bust_in_silhouette: Reply From: Ninfur

“get_viewport_rect().size” returns a Vector2. Since there is no property called height on Vector2, that error is shown.

Do you perhaps want y?

get_viewport_rect().size.y

To check what properties are available, you can Ctrl+Left click on some part of the code, for example on “.size”, in the script editor. It will bring up the documentation page for that item

hi, thank you for the reply. im trying to get a background sprite to respawn back at the top of the screen for a vertical scrolling game.

im not sure how to make this work

kieranbramley | 2022-04-12 17:01

It looks like you pretty much got it. Just use size.y instead of size.height.

I just tested the following code, which will move the sprite to the top of the screen as soon as it’s below the viewport:

extends Sprite

func _process(delta):
	position.y += 500.0 * delta

	if position.y > get_viewport_rect().size.y:
		position.y = -200.0

Ninfur | 2022-04-14 13:49