Skip to content

Commit

Permalink
Fix wrong frames when play step animation (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiepengTan authored Jan 21, 2025
1 parent 4b18cbf commit e50c98a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/anim/anim.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (this *Anim) Update(delay float64) bool {
}
// Animating
from := 0
to := this.totalframe
to := this.totalframe - 1
// Compute ratio
rangeval := float64(to + 1 - from)
ratio := delay * float64(this.fps*this.speedRatio) / 1000.0
Expand Down
10 changes: 5 additions & 5 deletions sprite.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,9 +889,9 @@ func (p *SpriteImpl) goAnimateInternal(name SpriteAnimationName, ani *aniConfig,
if ani.AniType == aniTypeFrame {
p.goSetCostume(ani.From)
if ani.Fps == 0 { //compute fps
ani.Fps = math.Abs(tovalf-fromvalf) / ani.Duration
ani.Fps = math.Abs(tovalf-fromvalf+1) / ani.Duration
} else {
ani.Duration = math.Abs(tovalf-fromvalf) / ani.Fps
ani.Duration = math.Abs(tovalf-fromvalf+1) / ani.Fps
}
}

Expand All @@ -904,7 +904,7 @@ func (p *SpriteImpl) goAnimateInternal(name SpriteAnimationName, ani *aniConfig,

an := anim.NewAnim(name, fps, framenum, ani.IsLoop)
// create channels
defaultChannel := []*anim.AnimationKeyFrame{{Frame: 0, Value: fromval}, {Frame: framenum, Value: toval}}
defaultChannel := []*anim.AnimationKeyFrame{{Frame: 0, Value: fromval}, {Frame: framenum - 1, Value: toval}}
switch ani.AniType {
case aniTypeFrame:
an.AddChannel(AnimChannelFrame, anim.AnimValTypeInt, defaultChannel)
Expand All @@ -920,8 +920,8 @@ func (p *SpriteImpl) goAnimateInternal(name SpriteAnimationName, ani *aniConfig,
iFrameTo := int(math.Round(frameTo))
frameCount := iFrameTo - iFrameFrom + 1
framePerIter := int(float64(frameCount) * ani.Fps / float64(ani.FrameFps))
iterCount := int(framenum / framePerIter)
is_need_ext := framenum != iterCount*int(ani.FrameFps)
iterCount := (framenum + 1) / framePerIter
is_need_ext := (framenum + 1) != iterCount*framePerIter
arySize := iterCount * 2
if is_need_ext {
arySize += 2
Expand Down

0 comments on commit e50c98a

Please sign in to comment.