Closed umbe1987 closed 3 years ago
What's the crash?
I solved. It was an issue in my code. I was waiting for events and storing x y position with ev.pos afterwards, but I did not check which type of event. So basically with the mouse from desktop everything worked while some different unkown event from mobile which did not have pos attribute caused the app to "crash" (going to background) as soon as I touched the screen. I'm on mobile so I can't provide the code but I'll come back when I'll be in front of my laptop. I committed a working code to my repo (see link above).
Ok, so the problem was related to these lines in the main loop:
# If not sleeping, draw the screen.
if not sleeping:
hero.move(joypad.btn_pressed(ev))
which I changed to:
if not sleeping:
if ev.type == pygame.MOUSEMOTION or ev.type == pygame.MOUSEBUTTONUP:
hero.move(joypad.btn_pressed(ev))
Now, x, y = ev.pos
in Joypad.btn_pressed()
method does not goes in error if the event is something without the "pos" attribute (e.g a QUIT event).
My updated code is in my repo if you wanna see it.
You can close the issue if you want, thanks!
I opened the same issue at rapt-pygame-example but I am copying it here as I think it's more related to this repo. Sorry for double posting...
I made a game which uses
pygame.mouse.get_pressed()
to check whether the mouse left button is pressed. The complete code is in my repo. If this happens, it checks whether the position of the click is LEFT RIGH UP or DOWN of a joypad draw. This moves a character towards the correct direction. The game works when I test it on my Ubuntu machine, but it crashes as soon as I touch whatever area of the screen on mobile (no matter if it's within the joypad's buttons or outside). I check for mouse left with the code below inside a Joypad class:Then, in the Character class I do:
Finally, in my main function I do: