Why is my game window invisible?

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

I just got Godot after being thoroughly confused by Unity as a beginner and I like it much better so far. But that’s beside the point. I’ve been following the Your First Game doc and I did everything that it said to do (and actually understood it). Once I get my player script working and play the player scene, nothing happens. The engine acts like it started, but it didn’t. Or at least I thought so. When I hover over the Godot icon on my PC’s taskbar, it shows 3 windows open, the Godot editor, the window that has all the gobbelty-gook and errors and stuff, and a window showing my game. When I hover over it, it doesn’t show anything. All this seems to suggest that my game is running but the window itself is invisible. I only have 1 script, the player script, and this is it:

extends Area2D # Not sure what this does but all 2D scripts have it.
# $ means the same thing as get_node().
# Export allows the variable to be changed in the Inspector, like adding public to a variable in C#.
# delta is the amount of time the previous frame took to complete, ensuring that movement stays consistent even when framerate changes.
# Clamping a value means restricting it to a certain range.

export var speed = 400 # How fast the player will move (pixels/sec).
var screen_size # Size of the game window.

func _ready(): # Called when a node enters the scene tree.
screen_size = get_viewport_rect().size # Sets screen_size to whatever the size of the window is.

func _process(delta): # Called every frame.
var velocity = Vector2() # The player's movement vector.
# Input.is_action_pressed() returns true or false based on whether or not the specified key is being pressed.
# velocity.x and velocity.y determine how fast the node is travelling up, down, left, or right. For x, positive is right and negative is left, for y, positive is down and negative is up.

if Input.is_action_pressed("ui_right"): # Determines if the player is pressing the right arrow key.
	velocity.x += 1 # Sets velocity.x to 1 and makes the player move right.

if Input.is_action_pressed("ui_left"): # Determines if the player is pressing the left arrow key.
	velocity.x -= 1 # Sets velocity.x to -1 and makes the player move left.

if Input.is_action_pressed("ui_down"): # Determines if the player is pressing the down arrow key.
	velocity.y += 1 # Sets velocity.y to 1 and makes the player move down.

if Input.is_action_pressed("ui_up"): # Determines if the player is pressing the up arrow key.
	velocity.y -= 1 # Sets velocity.y to -1 and makes the player move up.

if velocity.length() > 0: # Determines if the player is moving or not (I think).
	velocity = velocity.normalized() * speed # Not entirely sure but as far as I can tell this prevents moving faster diagonally than in any given straight direction.
	$AnimatedSprite.play() # Plays the animation.
else: # Just a standard else statement.
	$AnimatedSprite.stop() # Stops the animation.

position += velocity * delta # Moves the player to wherever it's supposed to be.
position.x = clamp(position.x, 0, screen_size.x) # Disables the player to go offscreen on the x axis.
position.y = clamp(position.y, 0, screen_size.y) # Disables the player to go offscreen on the y axis.

Please excuse the excessive amount of comments, this is my first Godot script and I just want to make sure I can remember what something does in case I forget. Thanks in advance for any answers!

Your script seems fine. Does this happen for all of your projects or just this one? Did running the game work before? Does it still happen after you restart Godot / your PC?

njamster | 2020-02-12 13:18

Sorry for this, after doing more research I found out I just had to set “allow hidpi” to true under Project Settings->Display->Window. So, uh, thanks for the theoretical help! And to answer your questions, it didn’t happen before, running the game never worked before, and it still happens after I restart.

MrKathooloo | 2020-02-20 23:43