Reputation: 9
I am running a script:
func _ready():
screensize.get_viewport().get_rect().size
set_process(true)
spawn_fruit(5)
I am getting an error: Nonexistent function get_viewport in base Nil I've seen this error on other peoples scripts for get_rect and other functions, but nothing for this. I am new to GoDot so go easy on me please:)
Upvotes: 0
Views: 1325
Reputation: 9
I just found the solution! In Godot 3.1+ you can't use get_rect() because it was removed. You have to write it as:
screensize = get_viewport().size
Second of all, you have to use f.translate instead of f.set_pos:
f.set_pos(Vector2(rand_range(10, screensize.width-10), rand_range(10, screensize.height-10)))
f.translate(Vector2(rand_range(300, screensize.x-800),rand_range(300, screensize.y-800)))
Thirdly, Vector2 does not use .width and .height anymore. It was changed to .x and .y (Shown Above)
Credit goes to LT Farms on YouTube
Upvotes: 0