ebiten: Ensure that Update is called at least once before Draw in the first frame

Fixes #1155
This commit is contained in:
Hajime Hoshi 2020-06-09 22:21:34 +09:00
parent 93ebb03b3c
commit a66867007a

View File

@ -50,6 +50,8 @@ type uiContext struct {
offscreen *Image
screen *Image
updateCalled bool
// scaleForWindow is the scale of a window. This doesn't represent the scale on fullscreen. This value works
// only on desktops.
//
@ -249,6 +251,12 @@ func (c *uiContext) Update(afterFrameUpdate func()) error {
func (c *uiContext) update(afterFrameUpdate func()) error {
updateCount := clock.Update(MaxTPS())
// Ensure that Update is called once before Draw so that Update can be used for initialization.
if !c.updateCalled && updateCount == 0 {
updateCount = 1
c.updateCalled = true
}
if game, ok := c.game.(interface{ Draw(*Image) }); ok {
for i := 0; i < updateCount; i++ {
c.updateOffscreen()