lordmauve / pgzero

A zero-boilerplate games programming framework for Python 3, based on Pygame.
https://pygame-zero.readthedocs.io/
GNU Lesser General Public License v3.0
530 stars 190 forks source link

Mouse position only reports up to 99 pixels #230

Closed JeremiahCheatham closed 2 years ago

JeremiahCheatham commented 3 years ago

I have been trying to understand why i can't get pygame zero to work on my computer. I have Computer Coding Python Games for kids book. While trying to do the projects with my son they were not working. At first it was my Ryzen based PC running Archlinux that wasn't working but our intel laptop with same OS was working. But when i switched to an internal ssd and reinstalled Archlinux it suddenly failed to work. I have a old chromebook with archlinux that does however work. All installed the same way all up to date. He is able to run the program correctly under windows but i do try to keep away from windows when possible so for the past month I have been trying to figure out what is causing this. I have used the standard archlinux packages and with pip for the final pygame zero. I also tried removing them and using pip for pygame numpy and pygame zero with same results. The issue is mouse position is not detected past 99 on the x and y so the only correct x,y is in the top left 99 sqare pixels of the screen. I have tested pygame to see if it's pygame fault but it seems to work. only pygame zero doesn't.

I have 3 files shooter.py is the file with the code from the book i also added a line to report mouse position. mousepygame.py test pygame mouse position to the best of my knowledge and it works all the way across the screen. mousepgzero.py is the pygame zero mouse test that only goes up to 99 for both x and y.

I would appreciate any input for trouble shooting this as i do wish to find the answer and I don't wish to use windows.

fruit shooter.tar.gz

lordmauve commented 3 years ago

If you want to hook into the Pygame event loop and see what coordinates you get, you could insert some code around here: https://github.com/lordmauve/pgzero/blob/df7c738d514e0e895aae22241d6b3769dc92e18b/pgzero/game.py#L258

However, I don't think Pygame Zero does anything to modify the coordinates you get from Pygame, so I suspect this is a Pygame or SDL problem.

lordmauve commented 3 years ago

For what it's worth all three of your programs work correctly for me on Ubuntu 20.04.

JeremiahCheatham commented 3 years ago

Like I said Archlinux with KDE and lts kernel on all my devices. Ryzen 2700 with nvidia gtx 1060 doesn't work on pygame zero but does on the pygame one. intel 8250U laptop with intel graphics same OS doesn't work but did in the past. HP chromebook 14 with old celernon same os all up to day does work on all. Since pygame is reporting the correct numbers but pygame zero is not it must be to do with pygame zero. the problem is i need pygame zero to work.

JeremiahCheatham commented 3 years ago

Lordmauve could you give me more info on how to insert that code. I am new to python.

JeremiahCheatham commented 3 years ago

I was wondering if it's some how the type of variable its storing like is it limited to 99 somehow.

JeremiahCheatham commented 3 years ago

Screenshot_20201011_113458 Screenshot_20201011_113531 Screenshot_20201011_113545 Screenshot_20201011_114539

tried to mark in red where the mouse was

lordmauve commented 3 years ago

I realise that this because we resize the window - it's 100x100 until the module has been executed. The reason is that we need a display surface to be able to convert sprites that are loaded at import time. So it's a Pygame bug: it hasn't properly reflected the resize.

What version of Pygame and SDL are you using?

JeremiahCheatham commented 3 years ago

sdl reports as 2.0.12 and pygame is 1.9.6 I tried both the archlinux package for pygame and also removed it and used the pip version with same results. I am confused how it can be a pygame bug when pygame is not having the but it seems to work fine.

JeremiahCheatham commented 3 years ago

For fun I tried adding WIDTH = 800 and HEIGHT = 600 but it didn't affect anything. I'm also using the stable version of pygame zero not any development version. install though pip

lordmauve commented 3 years ago

We use more features of Pygame than are shown in your "equivalent" code, so we hit more bugs.

You could try setting WIDTH and HEIGHT (using the global keyword) after a couple of frames. I think there's a possibility that we're resetting the size so quickly that there's a race condition.

JeremiahCheatham commented 3 years ago

global WIDTH, HEIGHT WIDTH = 800 HEIGHT = 600

Had no affect not sure if i wrote it correctly since i am not a programmer lol.

lordmauve commented 3 years ago

I mean after a couple of frames, like

def scale():
    global WIDTH, HEIGHT
    WIDTH = 800
    HEIGHT = 600
clock.schedule(scale, 0.05)

I'm not saying that's desirable but it would shed light on how this problem arises.

JeremiahCheatham commented 3 years ago

import pgzrun

def scale(): global WIDTH, HEIGHT WIDTH = 800 HEIGHT = 600 clock.schedule(scale, 0.05)

def on_mouse_move(pos): print(pos) pgzrun.go()

is my current code. Ran it for over minute without change.

JeremiahCheatham commented 3 years ago

my old chromebook that was working everytime before i posted is also doing the same thing. I am have done an update before rebooting so this is not the fresh boot. I tried to max out the old celeron with some video it can't play and it did launch python much slower but it still did the same. I am wondering if this is related to something else in the system like kernel or lower libraries? All 3 computers are using the archlinux long term support kernel because the new one seemed too unstable for me. The was additions into the kernel that actually broke other programs so i had enough of that. but it's still a 5.4.70 kernel

JeremiahCheatham commented 3 years ago

import` pgzrun

def scale(): global WIDTH, HEIGHT WIDTH = 800 HEIGHT = 601 clock.schedule(scale, 0.1)

def on_mouse_move(pos): print(pos) pgzrun.go()

This works. Note that 2 conditions must be met. It can not be 800x600. It has to be a different resolution. Also it must be 0.1 or longer shorter than 0.1 will not work. I tried on the mouse test and apple shoot both with same results both conditions must be there. So you may be right about that setup too fast. But it ignores changing a resolution to one that is already the default.

lordmauve commented 3 years ago

Pygame 1.9.6 does not build with SDL2; can you find the version of SDL1.2 your Pygame uses? Also when you install with pip, is that installing manylinux wheels?

JeremiahCheatham commented 3 years ago

my sdl1 version is sdl-1.2.15. I think there was an error about not having wheels when i installed with pip so I am guessing no since I didn't know what wheels was. i use wheel for sudo group that's all i know.

JeremiahCheatham commented 3 years ago

Ok I installed python-wheel. I uninstalled pygame numpy and pgzero that i had installed before with pip and reinstalled them this time it gave me the wheel version. but i have the exact same result.

JeremiahCheatham commented 3 years ago

Is there anything else i can try to see what is causing this issue and why the 3 computers here all do it but yours doesn't. Are we using the same versions of software?

lordmauve commented 2 years ago

We now quit the original 100x100 window before creating the new one. This, and the upgrade to Pygame 2.1 (which only supports SDL2) means I think this issue should now be fixed. We can reopen if it is not.