mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
ebiten: Ensure that Update is called at least once before Draw in the first frame
Fixes #1155
This commit is contained in:
parent
93ebb03b3c
commit
a66867007a
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user