MCPcopy Index your code
hub / github.com/EngoEngine/engo / Update

Method Update

common/camera.go:429–458  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

427// of the screen, the camera moves towards that edge.
428// TODO: Warning doesn't get the cursor position
429func (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.
461type MouseZoomer struct {

Callers

nothing calls this directly

Calls 5

CursorPosFunction · 0.92
GameWidthFunction · 0.92
GameHeightFunction · 0.92
SqrtFunction · 0.92
DispatchMethod · 0.80

Tested by

no test coverage detected