- Edited
Hello there,
I am a bit new so sorry if this is a dumb question.
I have been trying to follow along with some tutorials and was using some code from https://github.com/Godot-Tutorials/Movement-No-Input-Solution/blob/master/Hero.gd
At the top of this script, the author begins the script by defining the window size.
extends Sprite
var gameWidth: int = OS.get_window_size().x
var gameHeight: int = OS.get_window_size().y
When I try doing this however in 4.0, I get an error saying cannot call function get_size() on a null value.
Here is my code
extends Sprite2D
var gameWidth: int = get_window().get_size().x
var gameHeight: int = get_window().get_size().y
var spriteWidth: int = get_texture().get_width()
var spriteHeight: int = get_texture().get_height()
@export var velocity: float = 100.0
@export var acceleration: float = 300.0
@export var max_speed: float = 1500.0
func _enter_tree():
positionLeftCenter()
How come I am unable to use the get_window() function at this point of my script yet the get_texture() works just fine. In the debugger it also says at function: @implicit_new.
The following however works just fine
extends Sprite2D
var gameWidth: int
var gameHeight: int
@export var velocity: float = 100.0
@export var acceleration: float = 300.0
@export var max_speed: float = 1500.0
func _enter_tree():
gameWidth = get_window().get_size().x
gameHeight = get_window().get_size().y
positionMiddle()
Any help welcome!