Skip to content
Advertisement

Object escapes the window in pygame . How to prevent it from doing so?

So, I am python beginner and wanted to create a space invader game. But I’m facing an issue.

The player object escapes the pygame window if I press the left arrow key or the right arrow key for a longer duration of time.

Here’s my code –

JavaScript

Before asking this question I’ve tried this but it doesn’t seems to restrict the spaceship within the window

JavaScript

Any ideas how to fix it up?

Advertisement

Answer

I CHANGED

JavaScript

TO

JavaScript

AND IT WORKED PERFECTLY FOR ME

BEFORE

JavaScript

AFTER

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement