JoelOtter / termloop

Terminal-based game engine for Go, built on top of Termbox
Other
1.42k stars 83 forks source link

Screen size not returned correctly #61

Closed wolfshirts closed 2 years ago

wolfshirts commented 2 years ago

Maybe just an issue with my code, but I seem to be getting 0 back for game.Screen().Size() both width, and height.

JoelOtter commented 2 years ago

Please post a minimal executable code sample which reproduces this bug :)

wolfshirts commented 2 years ago

Absolutely. Thanks!

import (
    "fmt"

    tl "github.com/JoelOtter/termloop"
)

func main() {
    game := tl.NewGame()
    game.Screen().SetFps(30)
    x, y := game.Screen().Size()
    textToDisplay := fmt.Sprintf("Current size x: %d y: %d", x, y)
    text := tl.NewText(10, 10, textToDisplay, tl.ColorBlack, tl.ColorBlue)
    game.Screen().AddEntity(text)
    game.Start()
}
Screen Shot 2021-11-23 at 8 08 58 PM
aquilax commented 2 years ago

Looks like the same issue as https://github.com/JoelOtter/termloop/issues/13

TLDR: Screen size is not initialized before game.Start() here https://github.com/JoelOtter/termloop/blob/master/game.go#L89

JoelOtter commented 2 years ago

Yep that'll do it :) Until the game has actually started Termloop doesn't know anything about your terminal. Should probably document that but I am still vaguely intending to do a full rewrite of this library given it's very old at this point...