mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +01:00
mobile: Add UpdateTouchesOnAndroid
This commit is contained in:
parent
4d8897b785
commit
d72a71877a
@ -29,9 +29,7 @@ type EventDispatcher interface {
|
|||||||
SetScreenSize(width, height int)
|
SetScreenSize(width, height int)
|
||||||
SetScreenScale(scale int)
|
SetScreenScale(scale int)
|
||||||
Render() error
|
Render() error
|
||||||
TouchDown(id int, x, y int)
|
UpdateTouchesOnAndroid(action int, id int, x, y int)
|
||||||
TouchMove(id int, x, y int)
|
|
||||||
TouchUp(id int)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start starts the game and returns immediately.
|
// Start starts the game and returns immediately.
|
||||||
@ -84,20 +82,30 @@ func (t touch) Position() (int, int) {
|
|||||||
t.position.y / ui.CurrentUI().ScreenScale()
|
t.position.y / ui.CurrentUI().ScreenScale()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *eventDispatcher) TouchDown(id int, x, y int) {
|
// UpdateTouchesOnAndroid updates the touch state on Android.
|
||||||
|
//
|
||||||
|
// This should be called with onTouchEvent of GLSurfaceView like this:
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public boolean onTouchEvent(MotionEvent e) {
|
||||||
|
// for (int i = 0; i < e.getPointerCount(); i++) {
|
||||||
|
// int id = e.getPointerId(i);
|
||||||
|
// int x = (int)e.getX(i);
|
||||||
|
// int y = (int)e.getY(i);
|
||||||
|
// YourGame.CurrentEventDispatcher().UpdateTouchesOnAndroid(e.getActionMasked(), id, x, y);
|
||||||
|
// }
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
func (e *eventDispatcher) UpdateTouchesOnAndroid(action int, id int, x, y int) {
|
||||||
|
switch action {
|
||||||
|
case 0x00, 0x05, 0x02: // ACTION_DOWN, ACTION_POINTER_DOWN, ACTION_MOVE
|
||||||
e.touches[id] = position{x, y}
|
e.touches[id] = position{x, y}
|
||||||
e.updateTouches()
|
e.updateTouches()
|
||||||
}
|
case 0x01, 0x06: // ACTION_UP, ACTION_POINTER_UP
|
||||||
|
|
||||||
func (e *eventDispatcher) TouchMove(id int, x, y int) {
|
|
||||||
e.touches[id] = position{x, y}
|
|
||||||
e.updateTouches()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *eventDispatcher) TouchUp(id int) {
|
|
||||||
delete(e.touches, id)
|
delete(e.touches, id)
|
||||||
e.updateTouches()
|
e.updateTouches()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (e *eventDispatcher) updateTouches() {
|
func (e *eventDispatcher) updateTouches() {
|
||||||
ts := []ui.Touch{}
|
ts := []ui.Touch{}
|
||||||
|
Loading…
Reference in New Issue
Block a user