mirror of
https://codeberg.org/scip/golsky.git
synced 2025-12-17 12:40:56 +01:00
fix flickering
This commit is contained in:
16
src/game.go
16
src/game.go
@@ -10,7 +10,6 @@ type Game struct {
|
|||||||
CurrentScene SceneName
|
CurrentScene SceneName
|
||||||
Config *Config
|
Config *Config
|
||||||
Scale float32
|
Scale float32
|
||||||
Screen *ebiten.Image
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGame(config *Config, startscene SceneName) *Game {
|
func NewGame(config *Config, startscene SceneName) *Game {
|
||||||
@@ -24,10 +23,10 @@ func NewGame(config *Config, startscene SceneName) *Game {
|
|||||||
// setup scene[s]
|
// setup scene[s]
|
||||||
game.CurrentScene = startscene
|
game.CurrentScene = startscene
|
||||||
game.Scenes[Play] = NewPlayScene(game, config)
|
game.Scenes[Play] = NewPlayScene(game, config)
|
||||||
|
game.Scenes[Toolbar] = NewToolbarScene(game, config)
|
||||||
game.Scenes[Menu] = NewMenuScene(game, config)
|
game.Scenes[Menu] = NewMenuScene(game, config)
|
||||||
game.Scenes[Options] = NewOptionsScene(game, config)
|
game.Scenes[Options] = NewOptionsScene(game, config)
|
||||||
game.Scenes[Keybindings] = NewKeybindingsScene(game, config)
|
game.Scenes[Keybindings] = NewKeybindingsScene(game, config)
|
||||||
game.Scenes[Toolbar] = NewToolbarScene(game, config)
|
|
||||||
|
|
||||||
// setup environment
|
// setup environment
|
||||||
ebiten.SetWindowSize(game.ScreenWidth, game.ScreenHeight)
|
ebiten.SetWindowSize(game.ScreenWidth, game.ScreenHeight)
|
||||||
@@ -35,7 +34,6 @@ func NewGame(config *Config, startscene SceneName) *Game {
|
|||||||
ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
|
ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
|
||||||
ebiten.SetScreenClearedEveryFrame(true)
|
ebiten.SetScreenClearedEveryFrame(true)
|
||||||
|
|
||||||
game.Screen = ebiten.NewImage(game.ScreenWidth, game.ScreenHeight)
|
|
||||||
return game
|
return game
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,13 +48,18 @@ func (game *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (game *Game) Update() error {
|
func (game *Game) Update() error {
|
||||||
scene := game.GetCurrentScene()
|
for _, scene := range game.Scenes {
|
||||||
|
if scene.IsPrimary() {
|
||||||
|
if quit := scene.Update(); quit != nil {
|
||||||
|
return quit
|
||||||
|
}
|
||||||
|
|
||||||
if quit := scene.Update(); quit != nil {
|
}
|
||||||
return quit
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scene := game.GetCurrentScene()
|
||||||
next := scene.GetNext()
|
next := scene.GetNext()
|
||||||
|
|
||||||
if next != game.CurrentScene {
|
if next != game.CurrentScene {
|
||||||
game.Scenes[next].SetPrevious(game.CurrentScene)
|
game.Scenes[next].SetPrevious(game.CurrentScene)
|
||||||
scene.ResetNext()
|
scene.ResetNext()
|
||||||
@@ -77,6 +80,7 @@ func (game *Game) Draw(screen *ebiten.Image) {
|
|||||||
if current == game.CurrentScene {
|
if current == game.CurrentScene {
|
||||||
// avoid to redraw it in the next step
|
// avoid to redraw it in the next step
|
||||||
skip = true
|
skip = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/play.go
10
src/play.go
@@ -19,7 +19,7 @@ type Images struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DEBUG_FORMAT = "FPS: %0.2f, TPG: %d, M: %0.2fMB, Generations: %d\nScale: %.02f, Zoom: %d, Cam: %.02f,%.02f Cursor: %d,%d %s"
|
DEBUG_FORMAT = "FPS: %0.2f, TPG: %d, M: %0.2fMB, Generations: %d\nScale: %.02f, Zoom: %d, Cam: %.02f,%.02f Cursor: %d,%d %s, UI Active: %t"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ScenePlay struct {
|
type ScenePlay struct {
|
||||||
@@ -485,10 +485,8 @@ func (scene *ScenePlay) Draw(screen *ebiten.Image) {
|
|||||||
|
|
||||||
scene.DrawDebug(screen)
|
scene.DrawDebug(screen)
|
||||||
|
|
||||||
op.GeoM.Reset()
|
// draw the toolbar directly from here, because otherwise it flickers
|
||||||
op.GeoM.Translate(0, 0)
|
scene.Game.Scenes[Toolbar].Draw(screen)
|
||||||
|
|
||||||
scene.Game.Screen.DrawImage(screen, op)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (scene *ScenePlay) DrawEvolution(screen *ebiten.Image, x, y int, op *ebiten.DrawImageOptions) {
|
func (scene *ScenePlay) DrawEvolution(screen *ebiten.Image, x, y int, op *ebiten.DrawImageOptions) {
|
||||||
@@ -556,7 +554,7 @@ func (scene *ScenePlay) DrawDebug(screen *ebiten.Image) {
|
|||||||
scene.Game.Scale, scene.Camera.ZoomFactor,
|
scene.Game.Scale, scene.Camera.ZoomFactor,
|
||||||
scene.Camera.Position[0], scene.Camera.Position[1],
|
scene.Camera.Position[0], scene.Camera.Position[1],
|
||||||
x, y,
|
x, y,
|
||||||
paused)
|
paused, uiinput.UIActive)
|
||||||
|
|
||||||
FontRenderer.Renderer.SetSizePx(10 + int(scene.Game.Scale*10))
|
FontRenderer.Renderer.SetSizePx(10 + int(scene.Game.Scale*10))
|
||||||
FontRenderer.Renderer.SetTarget(screen)
|
FontRenderer.Renderer.SetTarget(screen)
|
||||||
|
|||||||
Reference in New Issue
Block a user