Skip to content
This repository has been archived by the owner on Jan 11, 2019. It is now read-only.

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

Closed
rubendahl opened this issue May 20, 2013 · 2 comments
Closed

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

rubendahl opened this issue May 20, 2013 · 2 comments
Labels

Comments

@rubendahl
Copy link

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
Copy link
Author

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
Copy link
Owner

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant