Update moves the camera based on the position of the mouse. If the mouse is on the edge of the screen, the camera moves towards that edge. TODO: Warning doesn't get the cursor position
(dt float32)
| 427 | // of the screen, the camera moves towards that edge. |
| 428 | // TODO: Warning doesn't get the cursor position |
| 429 | func (c *EdgeScroller) Update(dt float32) { |
| 430 | curX, curY := engo.CursorPos() |
| 431 | maxX, maxY := engo.GameWidth(), engo.GameHeight() |
| 432 | |
| 433 | if curX < c.EdgeMargin && curY < c.EdgeMargin { |
| 434 | s := math.Sqrt(2) |
| 435 | engo.Mailbox.Dispatch(CameraMessage{Axis: XAxis, Value: -c.ScrollSpeed * dt / s, Incremental: true}) |
| 436 | engo.Mailbox.Dispatch(CameraMessage{Axis: YAxis, Value: -c.ScrollSpeed * dt / s, Incremental: true}) |
| 437 | } else if curX < c.EdgeMargin && curY > maxY-c.EdgeMargin { |
| 438 | s := math.Sqrt(2) |
| 439 | engo.Mailbox.Dispatch(CameraMessage{Axis: XAxis, Value: -c.ScrollSpeed * dt / s, Incremental: true}) |
| 440 | engo.Mailbox.Dispatch(CameraMessage{Axis: YAxis, Value: c.ScrollSpeed * dt / s, Incremental: true}) |
| 441 | } else if curX > maxX-c.EdgeMargin && curY < c.EdgeMargin { |
| 442 | s := math.Sqrt(2) |
| 443 | engo.Mailbox.Dispatch(CameraMessage{Axis: XAxis, Value: c.ScrollSpeed * dt / s, Incremental: true}) |
| 444 | engo.Mailbox.Dispatch(CameraMessage{Axis: YAxis, Value: -c.ScrollSpeed * dt / s, Incremental: true}) |
| 445 | } else if curX > maxX-c.EdgeMargin && curY > maxY-c.EdgeMargin { |
| 446 | s := math.Sqrt(2) |
| 447 | engo.Mailbox.Dispatch(CameraMessage{Axis: XAxis, Value: c.ScrollSpeed * dt / s, Incremental: true}) |
| 448 | engo.Mailbox.Dispatch(CameraMessage{Axis: YAxis, Value: c.ScrollSpeed * dt / s, Incremental: true}) |
| 449 | } else if curX < c.EdgeMargin { |
| 450 | engo.Mailbox.Dispatch(CameraMessage{Axis: XAxis, Value: -c.ScrollSpeed * dt, Incremental: true}) |
| 451 | } else if curX > maxX-c.EdgeMargin { |
| 452 | engo.Mailbox.Dispatch(CameraMessage{Axis: XAxis, Value: c.ScrollSpeed * dt, Incremental: true}) |
| 453 | } else if curY < c.EdgeMargin { |
| 454 | engo.Mailbox.Dispatch(CameraMessage{Axis: YAxis, Value: -c.ScrollSpeed * dt, Incremental: true}) |
| 455 | } else if curY > maxY-c.EdgeMargin { |
| 456 | engo.Mailbox.Dispatch(CameraMessage{Axis: YAxis, Value: c.ScrollSpeed * dt, Incremental: true}) |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | // MouseZoomer is a System that allows for zooming when the scroll wheel is used. |
| 461 | type MouseZoomer struct { |
nothing calls this directly
no test coverage detected