Skip to content

Commit 6358b96

Browse files
committed
Fix input pos
1 parent 6e752e4 commit 6358b96

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

internal/engine/sync.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,28 @@ func SyncNewSprite(obj any, pos Vec2) *Sprite {
2121
}
2222

2323
func SyncBindUI[T any](parentNode gdx.Object, path string) *T {
24-
2524
return gdx.BindUI[T](parentNode, path)
2625
}
2726
func SyncGetTimeScale() float64 {
2827
return gdx.PlatformMgr.GetTimeScale()
2928
}
3029
func SyncGetMousePos() Vec2 {
31-
return gdx.InputMgr.GetGlobalMousePos()
30+
return inputMgr.SyncGetGlobalMousePos()
3231
}
3332

3433
func SyncSetCameraPosition(pos Vec2) {
35-
gdx.CameraMgr.SetCameraPosition(NewVec2(pos.X, -pos.Y))
34+
cameraMgr.SyncSetCameraPosition(pos)
3635
}
3736

3837
func SyncScreenToWorld(pos Vec2) Vec2 {
3938
zoom := gdx.CameraMgr.GetCameraZoom().X
40-
camPos := gdx.CameraMgr.GetCameraPosition()
41-
camPos.Y *= -1
39+
camPos := cameraMgr.SyncGetCameraPosition()
4240
return pos.Divf(zoom / windowScale).Add(camPos.Mulf(windowScale))
4341
}
4442

4543
func SyncWorldToScreen(pos Vec2) Vec2 {
4644
zoom := gdx.CameraMgr.GetCameraZoom().X
47-
camPos := gdx.CameraMgr.GetCameraPosition()
48-
camPos.Y *= -1
45+
camPos := cameraMgr.SyncGetCameraPosition()
4946
return pos.Sub(camPos.Mulf(windowScale)).Mulf(zoom / windowScale)
5047
}
5148

internal/enginewrap/coord_adapter.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,30 @@ func (pself *PhysicMgrImpl) CheckCollisionCircle(pos Vec2, radius float64, colli
201201
// ============================================================================
202202
// InputMgr Coordinate Adapters
203203
// ============================================================================
204+
func (pself *InputMgrImpl) SyncGetGlobalMousePos() Vec2 {
205+
return flipY(gdx.InputMgr.GetGlobalMousePos())
206+
}
204207

205208
func (pself *InputMgrImpl) GetGlobalMousePos() Vec2 {
206209
return flipY(pself.inputMgrImpl.GetGlobalMousePos())
207210
}
208211

212+
// ============================================================================
213+
// CameraMgr Coordinate Adapters
214+
// ============================================================================
215+
func (pself *CameraMgrImpl) GetCameraPosition() Vec2 {
216+
return flipY(pself.cameraMgrImpl.GetCameraPosition())
217+
}
218+
func (pself *CameraMgrImpl) SetCameraPosition(position Vec2) {
219+
pself.cameraMgrImpl.SetCameraPosition(flipY(position))
220+
}
221+
func (pself *CameraMgrImpl) SyncGetCameraPosition() Vec2 {
222+
return flipY(gdx.CameraMgr.GetCameraPosition())
223+
}
224+
func (pself *CameraMgrImpl) SyncSetCameraPosition(position Vec2) {
225+
gdx.CameraMgr.SetCameraPosition(flipY(position))
226+
}
227+
209228
// ============================================================================
210229
// DebugMgr Coordinate Adapters
211230
// ============================================================================

0 commit comments

Comments
 (0)