JoelOtter / termloop

Terminal-based game engine for Go, built on top of Termbox

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Screen size not returned correctly

wolfshirts opened this issue · comments

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

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

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

Looks like the same issue as #13

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

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...