0 votes
var maximize = OS.is_window_maximized()
var set_max_size = OS.set_window_maximized()

func _process(delta):
    if maximize == false:
        set_max_size = true

I finished the code for pixel perfect scaling for my game, yet the function to make the game maximized at start (I run into performance issues when starting the game in fullscreen mode. 27 FPS fullscreen as opposed to 60 maximized) gives me the following error:

Invalid call to function 'set_window_maximized' in base '_OS'. Expected 1 arguments.
in Engine by (230 points)

1 Answer

+4 votes

As the error says, OS.set_window_maximized() takes one argument. Opening the editor help (click Search Help in the top-right corner of the script editor) tells you that the argument is a boolean:

OS.set_window_maximized() documentation

So, you should be using OS.set_window_maximized(true) to maximize the game window. Since this function doesn't return anything, there is no point in assigning its result to a variable.

Moreover, you should not be calling window management functions every frame (which can result in performance decreases); it's better to call them just once when needed.

by (12,835 points)

Thanks. But now I'm running into the problem where my FPS is dropping to about 27 like with fullscreen... Is there another display driver that I could use? I'm running on an nVidia 1050ti. I shouldn't have trouble running a game at 60 FPS that's only 256x224 with maybe 3 scripts implemented thus far.

What does your code look like after following Calinou's suggestions?
Performance drops are not just caused by a high number of objects, but what is going on in your code; especially mainloop operations like _process().
What is running in _process() on your scripts? You're right, you should have no trouble playing your game at 60+ FPS, unless something really Ugly is going on in your script...

extends Node2D

onready var root = get_tree().get_root()
onready var base_size = root.get_rect().size


func _ready():
    OS.set_window_maximized(true)
    get_tree().connect("screen_resized", self, "_on_screen_resized")

    root.set_as_render_target(true)
    root.set_render_target_update_mode(root.RENDER_TARGET_UPDATE_ALWAYS)
    root.set_render_target_to_screen_rect(root.get_rect())

func _on_screen_resized():

    var new_window_size = OS.get_window_size()

    var scale_w = max(int(new_window_size.x / base_size.x), 1)
    var scale_h = max(int(new_window_size.y / base_size.y), 1)
    var scale = min(scale_w, scale_h)

    var diff = new_window_size - (base_size * scale)
    var diffhalf = (diff * 0.5).floor()

    root.set_rect(Rect2(diffhalf, base_size))
    root.set_render_target_to_screen_rect(Rect2(diffhalf, base_size * scale))

This is the code for my game's world scene.

extends KinematicBody2D

###GRAB THE PLAYER SPRITE###
onready var player = get_node("MegaMan")
onready var player_offset = player.get_offset()
onready var pos = player.get_global_pos()
onready var debug_fps = get_node("Debug/FPS")
onready var debug_xpos = get_node("Debug/XPos")
onready var debug_ypos = get_node("Debug/YPos")
onready var debug_offset = get_node("Debug/Offset")
onready var debug_anim = get_node("Debug/Anim")
onready var debug_xspd = get_node("Debug/XSpeed")
onready var debug_yspd = get_node("Debug/YSpeed")


###DEBUG MODE VARIABLES###
var debug_mode = 0



###SET PLAYER VARIABLES###
var player_pos = pos
var direction = 0
var last_dir = 0
var anim = "idle"
var speed = Vector2()
var velocity = Vector2()
var jump_count = 0
var jump_hold = false
var final_grav
var allow_move = false
var beam_speed = 8
var weapon = 0
var charge = 0
var shoot_frame = 0

const X_SPEED = 1.3
const SLIDE_SPEED = 2.5
const GRAVITY = 0.25
const JUMP_FORCE = -5.25
const MAX_YSPEED = 7
const MAX_JUMPS = 1

###SET PROCESSES TO TRUE###
func _ready():
    set_process(true)
    set_fixed_process(true)
    set_process_input(true)

###HANDLE ONE TIME ANIMATIONS###
func _on_anim_finished():
    if anim == "teleport" and allow_move == false:
        allow_move = true
        anim = "idle"
        player.set_flip_h(true)
        player.play(anim)

    if anim == "lilstep" and direction != 0:
        anim = "run"
        player.play(anim)

    if anim == "lilstep" and direction == 0:
        anim = "idle"
        player.play(anim)

###ONE TIME EVENTS###
func _input(event):
    if allow_move == true:
        if jump_count < MAX_JUMPS and event.is_action_pressed("jump"):
            jump_hold = true
            speed.y = JUMP_FORCE
            jump_count += 1
            anim = "jump"
            player.play(anim)

func _process(delta):
    debug_fps.set_text(str(OS.get_frames_per_second()))
    debug_offset.set_text(str(player_offset))
    debug_xpos.set_text(str(pos.x))
    debug_ypos.set_text(str(pos.y))
    debug_anim.set_text(str(anim))
    debug_xspd.set_text(str(speed.x))
    debug_yspd.set_text(str(speed.y))


###HANDLE PLAYER INPUT AND MOVEMENT###
func _fixed_process(delta):
    ###TELEPORT THE PLAYER IN###
    if allow_move == false and player_offset.y < 0:
        player_offset.y += 8
        player.edit_set_pivot(player_offset)
    if allow_move == false and player_offset.y == 0:
        anim = "teleport"
        player.play(anim)

    if allow_move == true:
        ###SET THE DIRECTION OF THE PLAYER###
        if Input.is_action_pressed("move_left"):
            direction = -1
            player.set_flip_h(false)
        elif Input.is_action_pressed("move_right"):
            direction = 1
            player.set_flip_h(true)
        else:
            direction = 0

        ###ACTIVATE THE LITTLE STEP###
        if anim == "idle" and direction == -1 and last_dir != direction:
            anim = "lilstep"
            last_dir = direction
            move(Vector2(-1, 0))
            player.play(anim)
        elif anim == "idle" and direction == 1 and last_dir != direction:
            anim = "lilstep"
            last_dir = direction
            move(Vector2(1, 0))
            player.play(anim)
        elif anim == "run" and direction == -1 and last_dir != direction:
            anim = "lilstep"
            last_dir = direction
            move(Vector2(-1, 0))
            player.play(anim)
        elif anim == "run" and direction == 1 and last_dir != direction:
            anim = "lilstep"
            last_dir = direction
            move(Vector2(1, 0))
            player.play(anim)
        elif anim == "lilstep" and direction == -1 and last_dir != direction:
            anim = "lilstep"
            last_dir = direction
            move(Vector2(-1, 0))
            player.play(anim)
        elif anim == "lilstep" and direction == 1 and last_dir != direction:
            anim = "lilstep"
            last_dir = direction
            move(Vector2(1, 0))
            player.play(anim)

        ###RESET THE DIRECTION VALUE###
        if direction == 0 and last_dir != direction:
            last_dir = 0

        ###CHECK TO SEE IF JUMP IS BEING HELD###
        if Input.is_action_pressed("jump"):
            jump_hold = true
        else:
            jump_hold = false

    ###SET PLAYER RUNNING SPEED###
    if direction == -1 and anim != "lilstep":
        speed.x = -X_SPEED
    elif direction == 1 and anim != "lilstep":
        speed.x = X_SPEED
    else:
        speed.x = 0

    ###SET JUMP VELOCITY###
    speed.y += GRAVITY
    if speed.y > MAX_YSPEED:
        speed.y = MAX_YSPEED

    ###IF PLAYER RELEASED JUMP, START TO FALL###
    if jump_hold == false and speed.y < -1:
        speed.y = (speed.y - int(speed.y))

    ###MOVE THE PLAYER###
    velocity = Vector2(speed.x, speed.y)
    var move_remainder = move(velocity)

    var colliding = is_colliding()

    if is_colliding():
        var normal = get_collision_normal()
        var final_move = normal.slide(move_remainder)
        speed = normal.slide(speed)
        move(final_move)

        if normal == Vector2(0, -1) and direction != 0 and anim == "jump":
            jump_count = 0
            anim = "run"
            player.play(anim)
        elif normal == Vector2(0, -1) and direction == 0 and anim == "jump":
            jump_count = 0
            anim = "idle"
            player.play(anim)

###HANDLE ANIMATION CHANGES###
    if allow_move == true and direction == 0 and anim == "run":
        anim = "lilstep"
        player.play(anim)

    if allow_move == true and colliding == false and anim != "jump":
        jump_count = MAX_JUMPS
        anim = "jump"
        player.play(anim)

This is from my player script.

    extends TextureFrame

###PAUSE SCREEN STATE###
var pause_state = 0

func _ready():
    set_process_input(true)

func _input(event):
    ###ACTIVATE/DEACTIVATE PAUSE###
    if event.is_action_pressed("ui_accept"):
        pause_state +=1
    ###SHOW/HIDE PAUSE MENU###
    if pause_state == 1:
        get_tree().set_pause(true)
        show()
    else:
        get_tree().set_pause(false)
        hide()

    if pause_state > 1:
        pause_state = 0

And finally, the start of the pause menu functions.

I'm pretty sure is has to do with how my GPU is running GLES2. Just ran the game from a cheap HP laptop with an Intel graphics card and it runs full speed.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.