Python Forum
[PyGame] Problem when moving game window
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Problem when moving game window
#11
Got it.

From this it looks like when I title grab the sprite keeps moving on its current vector until it is released. If I hold it longer the sprite just disappears of the edge of the screen. They don't collide or obey their AI. Every time it jumps, I'm grabbing the title bar. I tried to time my holds to keep the sprite on the screen.

https://github.com/Michaelm1789/All-my-s...Glitch.avi
Reply
#12
Yeah i cannot replicate that issue at all on my system. Are you 100% positive the code you are running is the same that is on your repo?
Recommended Tutorials:
Reply
#13
It is. Totally unchanged, and I only have the one copy. I can't imagine the problem being the code. Other people have followed this tutorial and there is no mention of this in the comments, nor is there anyone replying to my comment with the same experience. You ran it on Linux, the OP did it on Mac.

It's like the little circuit that does the vector calculation keeps repeating its last calculation while everything else is suspended. Then when it all starts up again the sprite positions are however many frames ahead of everything else. Could python hand it off to a piece of hardware that doesn't know it's supposed to pause? It does pause during a title grab, right? I might have a chip that isn't a perfect match with my OS. I don't know, I'm just talking out my ass really. It's just weird, and not it the quirky, fun way.
Reply
#14
Have you heard of such an issue @[Mekire] ?
Recommended Tutorials:
Reply
#15
Unless someone mentions another good idea....this may be a good candidate to bring up to the pygame developers and see what they say. They might have better knowledge on hardware issues, if that is the problem. I would start getting your hardware information before asking.

https://github.com/pygame/pygame/issues

or their IRC or mailing list is the way i contacted them.
Recommended Tutorials:
Reply
#16
I just tried your game on a windows laptop and replicated your issue. It appears to be a windows only issue. The first thing comes to mind is someone mentioned a long time ago the pygame math module was buggy. Ive always avoided the math module and created my own. If you do that and the issue goes away, then you know it is a bug in the math module of pygame. If the problem persists after that i would still contact pygame devs. The fact that it works as intended in linux/mac and not in windows seems to be a bug, not code related. Usually when that happens i would pinpoint the culprit at one of the 3rd party libraries. Pygame, Pytmx, etc.
Recommended Tutorials:
Reply
#17
I have found a half-solution! The following code makes the game pause when you click the window:

[Image: 1rmpv8.png]

courtesy of MattR0se (https://www.reddit.com/r/pygame/comments...he_window/)

I will admit that it is a bit clunky to look at, to make it look nicer I separate all my actual game loop stuff into its own function. It solved the issue for me (on Windows 11) and I hope it will for you too!
Reply
#18
(Jan-12-2020, 04:25 PM)michael1789 Wrote: When I start the program, the widow often opens off to the side and I need to move it to see the whole thing. I click the title bar, move the window, and when the game redraws all the sprites have moved and are in places they shouldn't be able to get to. This doesn't happen if the game is paused.

Is there a way to stop this or is it just something basic to python? Perhaps I can code it pause while the title bar is clicked on? If you know of how to code where the window should open on my monitor that would work, but I'd rather just fix the problem.

You can try handling the window positioning by setting a fixed start position using your GUI library (e.g., geometry in Tkinter or pygame.display.set_mode() with a position hint). To prevent sprite displacement when moving the window, consider pausing updates when WM_MOVE or an equivalent event is detected. If using Tkinter, root.bind("<Configure>", callback) can help detect window movements. Let me know which library you're using for a more precise solution!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Game restart problem senka_25 4 2,801 Jun-24-2024, 09:49 PM
Last Post: AdamHensley
  [PyGame] Problem With Entering Game Loop ElevenDecember 3 4,000 Jan-19-2020, 08:25 AM
Last Post: michael1789
  Snake Game - obstacle problem Samira 3 8,258 Oct-31-2019, 02:58 PM
Last Post: Samira
  [PyGame] Game Logic problem with a "The Game of Life" Replication Coda 2 3,961 Dec-24-2018, 09:26 AM
Last Post: Coda
  [PyGame] Pong game key.event problem erickDarko 2 5,025 Dec-12-2018, 03:17 PM
Last Post: erickDarko

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020