renpy / pygame_sdl2

Reimplementation of portions of the pygame API using SDL2.
GNU Lesser General Public License v2.1
326 stars 64 forks source link

Understanding pygame_sdl2.TOUCH_MOUSEID #85

Closed umbe1987 closed 3 years ago

umbe1987 commented 6 years ago

Hi,

in the documentation it reads:

The mouse events (MOUSEBUTTONDOWN, MOUSEMOTION, MOUSEBUTTONUP, and MOUSEWHEEL) have a which field that identifies the mouse that generated the event. When equal to pygame_sdl2.TOUCH_MOUSEID, the event was generated by a touch of the screen.

I am not familiar with the term "field ". Basically, I am trying to implement a Joypad with four buttons (UP, DOWN, RIGHT, LEFT) which is just a draw in the bottom left of the display. When the user touches (e.g.) RIGHT the character of the game must move to the right. I have implemented my code like so:

if ev.type == pygame.MOUSEMOTION or ev.type == pygame.MOUSEBUTTONDOWN or ev.type == pygame.TOUCH_MOUSEID:
    hero.move(joypad.btn_pressed(ev))

But I'm not really sure if this is the right way to go.

Just talking about the pygame_sdl2.TOUCH_MOUSEID: is it used how it is supposed to? My game works fine from desktop with the mouse, while on mobile is working but thwe movements are kind of messy (sometimes it moves the wrong way for instance...).

I guess it might be due to the fact that my finger is not like a mouse pointer and it's more like many conurrent clicks (is it?). And also is not "as thin as a pointer" (meaning that I can press by mistake more than one direction at a time I guess).

I just need to know more about this pygame_sdl2.TOUCH_MOUSEID possibly.

Thanks!

umbe1987 commented 6 years ago

Ok, I found it in SDL2 docs. https://wiki.libsdl.org/SDL_MouseButtonEvent. Still need to figure out how to handle this properly, but I'm pretty sure I will.