Framerate issues with Arcade

746 views Asked by At

So I'm making a platformer 2D game with Arcade, and for some reason, my game always goes ~30 FPS instead of going 60 FPS.

Not only that, when I press the left arrow key to move my character to the left, it goes down to ~4 FPS.

Code for my movement system (I had to make a camera)

def update(self, x):
    # update player
    if self.player != None:
        self.player.real_x += self.player.movement
        self.player.center_y -= gravityConstant

I use 'real_x' variable instead of using 'center_x' because of the camera. Ignore the fact that the gravity doens't acelerate and always make the character fall at a constant speed (will fix that).

The player will always be in the center of the screen:

    self.player.center_x = self.x / 2;

At first I thought it was that the movement of the Sprite caused lag, but when I added gravity, I noticed that the problem is only with the X axis movement. When the character falls due to gravity, it runs at 30 FPS, but when it is moving in any direction that isn't Y (X, -X) it will slow down the game to ~4 FPS.

My computer is pretty bad though, but I don't think it's the responsable for this framerate issues.

Specs: Processor: 1.58 GHz RAM: 3.99 / 4.00 GB

EDIT: This happens with both left and right movements. The movement is handled through a arcade.Window class.

Code of the functions:

def onKeyDown(self, symbol):
    if symbol == arcade.key.LEFT:
        self.movement = -self.walk_speed;
    elif symbol == arcade.key.RIGHT:
        self.movement = self.walk_speed;
    elif symbol == arcade.key.UP:
        self.jumping = True;

def onKeyUp(self, symbol):
    if symbol == arcade.key.LEFT:
        self.movement = 0;
    elif symbol == arcade.key.RIGHT:
        self.movement = 0;
    elif symbol == arcade.key.UP:
        self.jumping = False;

Code of the on_key_press and on_key_release:

def on_key_press(self, symbol, modifier):
    if self.player != None:
        self.player.onKeyDown(symbol);

def on_key_release(self, symbol, modifier):
    if self.player != None:
        self.player.onKeyUp(symbol);

Note: This works with Classes, so these functions are inside a Player Class.

1

There are 1 answers

3
Magnetic Pizza On

Do you mind putting the part of the code responsible for the movements?

also, check where you put things on screen, you want to make a variable, set it to the image, and call that var. as for it only happening when moving left , make sure the left script is the same as right but - instead of +.