Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Setup window resize handler to fix camera bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
eth0net committed Feb 17, 2021
1 parent 9ead0aa commit 69991cd
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion scenes/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (g *GameScene) Setup(u engo.Updater) {
tilemapURL, err,
)
}
common.CameraBounds = tilemap.Level.Bounds()
speedSystem.Level = tilemap.Level

player, err := entities.NewPlayer(entities.NewPlayerOptions{
Expand Down Expand Up @@ -111,6 +110,18 @@ func (g *GameScene) Setup(u engo.Updater) {

tilemap.AddTilesToWorld(g.World)
g.World.AddEntity(player)

engo.Mailbox.Listen("WindowResizeMessage", func(msg engo.Message) {
offsetX, offsetY := engo.GameWidth()/2, engo.GameHeight()/2
scaleX, scaleY := engo.GetGlobalScale().X, engo.GetGlobalScale().Y

bounds := tilemap.Level.Bounds()
bounds.Min.X += offsetX / scaleX
bounds.Min.Y += offsetY / scaleY
bounds.Max.X -= offsetX / scaleX
bounds.Max.Y -= offsetY / scaleY
common.CameraBounds = bounds
})
}

// Type returns a unique string representation of GameScene.
Expand Down

0 comments on commit 69991cd

Please sign in to comment.