mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +01:00
Refactoring: unify preUpdate and calling f
This commit is contained in:
parent
05eaec6dd9
commit
e2f528d206
@ -32,8 +32,14 @@ type graphicsContext struct {
|
|||||||
screenScale int
|
screenScale int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *graphicsContext) preUpdate() error {
|
func (c *graphicsContext) update(f func(*Image) error) error {
|
||||||
return c.screen.Clear()
|
if err := c.screen.Clear(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := f(c.screen); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *graphicsContext) postUpdate() error {
|
func (c *graphicsContext) postUpdate() error {
|
||||||
|
6
run.go
6
run.go
@ -98,11 +98,7 @@ func Run(f func(*Image) error, width, height, scale int, title string) error {
|
|||||||
}
|
}
|
||||||
for gameTime < now {
|
for gameTime < now {
|
||||||
gameTime += int64(time.Second / 60)
|
gameTime += int64(time.Second / 60)
|
||||||
|
if err := graphicsContext.update(f); err != nil {
|
||||||
if err := graphicsContext.preUpdate(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := f(graphicsContext.screen); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user