Fixed delta time implementation.
This commit is contained in:
parent
be9c3dc619
commit
8d8ce41e71
2 changed files with 10 additions and 4 deletions
|
@ -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() {
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue