mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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
|
||||
}
|
||||
|
||||
func (c *graphicsContext) preUpdate() error {
|
||||
return c.screen.Clear()
|
||||
func (c *graphicsContext) update(f func(*Image) error) error {
|
||||
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 {
|
||||
|
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 {
|
||||
gameTime += int64(time.Second / 60)
|
||||
|
||||
if err := graphicsContext.preUpdate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := f(graphicsContext.screen); err != nil {
|
||||
if err := graphicsContext.update(f); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user