diff --git a/src/cmd/test/main.go b/src/cmd/test/main.go index f0171ff..0b0e3c2 100644 --- a/src/cmd/test/main.go +++ b/src/cmd/test/main.go @@ -21,7 +21,7 @@ func NewPlayer() *Player { Object: &gx.Object{ T: gx.Transform { P: gx.Vector{1, 1}, - S: gx.Vector{1, 1}, + S: gx.Vector{5, 5}, }, }, Image: playerImg, @@ -30,7 +30,7 @@ func NewPlayer() *Player { } func (p *Player) Update(e *gx.Engine) { - p.Sprite.Object.T.P.Y += 0.1 + p.Sprite.Object.T.P.Y += 40 * e.DT() } func main() { diff --git a/src/gx/main.go b/src/gx/main.go index adf9557..c542ec5 100644 --- a/src/gx/main.go +++ b/src/gx/main.go @@ -70,15 +70,19 @@ func (e *Engine) AddBehaver(b Behaver) { e.behavers = append(e.behavers, b) } +func (e *engine) setNewDT() { + e.dt = time.Since(e.lastTime).Seconds() + e.lastTime = time.Now() +} + func (e *engine) Update() error { eng := (*Engine)(e) - e.dt = time.Since(e.lastTime).Seconds() + e.setNewDT() for _, v := range eng.behavers { v.Update(eng) //fmt.Println(v) } - e.lastTime = time.Now() return nil } @@ -106,6 +110,8 @@ func (e *Engine) Run() error { ebiten.SetWindowTitle(e.wcfg.Title) ebiten.SetWindowSize(e.wcfg.Width, e.wcfg.Height) + e.lastTime = time.Now() + return ebiten.RunGame((*engine)(e)) }