ebiten: Ensure that Layout is called before Update in the first frame

This commit is contained in:
Hajime Hoshi 2020-12-20 21:10:47 +09:00
parent 8003000976
commit ce24640da8
2 changed files with 4 additions and 2 deletions

2
run.go
View File

@ -50,6 +50,8 @@ type Game interface {
// //
// Layout is called almost every frame. // Layout is called almost every frame.
// //
// It is ensured that Layout is invoked before Update is called in the first frame.
//
// If Layout returns non-positive numbers, the caller can panic. // If Layout returns non-positive numbers, the caller can panic.
// //
// You can return a fixed screen size if you don't care, or you can also return a calculated screen size // You can return a fixed screen size if you don't care, or you can also return a calculated screen size

View File

@ -155,6 +155,8 @@ func (c *uiContext) Update() error {
} }
func (c *uiContext) update() error { func (c *uiContext) update() error {
c.updateOffscreen()
updateCount := clock.Update(MaxTPS()) updateCount := clock.Update(MaxTPS())
// Ensure that Update is called once before Draw so that Update can be used for initialization. // Ensure that Update is called once before Draw so that Update can be used for initialization.
@ -174,8 +176,6 @@ func (c *uiContext) update() error {
uiDriver().ResetForFrame() uiDriver().ResetForFrame()
} }
c.updateOffscreen()
if updateCount > 0 { if updateCount > 0 {
if IsScreenClearedEveryFrame() { if IsScreenClearedEveryFrame() {
c.offscreen.Clear() c.offscreen.Clear()