Era-Dorta / gosu-android

A Gosu implementation for Android devices, undergraduate project
MIT License
31 stars 2 forks source link

Touch event coordinates not relative to Gosu::Window size. #15

Closed rubendahl closed 11 years ago

rubendahl commented 11 years ago

Touch events (touch_began etc) report X and Y values relative to the SurfaceView size instead of the Gosu::Window size.

This was reproduced when creating a Gosu::Window with 320x240 size in landscape mode on an HTC, where I could get X values > 1000 (as I can move the touch outside the screen into soft-button area).

From logs: I/System.out( 649): MainGameWindow - 320, 240 I/System.out( 649): SurfaceView: 960, 540 I/System.out( 649): [GameScreen] draw... @ (1063, 531)

rubendahl commented 11 years ago

Quick-fix / workaround which can be done in sub-classes for Gosu::Window:

  def touch_ended(touch)
    touch = fix_relative_touch(touch)
  end

  def fix_relative_touch(touch)
    x = touch.x * self.width / @surface_view.width
    y = touch.y * self.height / @surface_view.height 
    touch.x = x
    touch.y = y
    touch
  end
Era-Dorta commented 11 years ago

Thanks for trying and reporting errors of Gosu Android. I managed to reproduced the bug but your solution did not work for me, so I went for a different approach. I'll update master right now, please check it out and reopen the issue if the fix did not work.