Skip to content

Commit

Permalink
Add RenderFromOrigin method to Animation (OpenDiablo2#317)
Browse files Browse the repository at this point in the history
* Configuration cleanup

* Cleanup

* Add RenderFromOrigin option
  • Loading branch information
FooSoft authored Feb 25, 2020
1 parent 6f2c212 commit 418c798
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions d2core/d2asset/animation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ type Animation struct {
lastFrameTime float64
playedCount int

compositeMode d2render.CompositeMode
colorMod color.Color
compositeMode d2render.CompositeMode
colorMod color.Color
originAtBottom bool

playMode playMode
playLength float64
Expand Down Expand Up @@ -116,8 +117,9 @@ func createAnimationFromDCC(dcc *d2dcc.DCC, palette *d2datadict.PaletteRec, tran

func createAnimationFromDC6(dc6 *d2dc6.DC6File) (*Animation, error) {
animation := &Animation{
playLength: 1.0,
playLoop: true,
playLength: 1.0,
playLoop: true,
originAtBottom: true,
}

for frameIndex, dc6Frame := range dc6.Frames {
Expand Down Expand Up @@ -218,6 +220,17 @@ func (a *Animation) Render(target d2render.Surface) error {
return target.Render(frame.image)
}

func (a *Animation) RenderFromOrigin(target d2render.Surface) error {
if a.originAtBottom {
direction := a.directions[a.directionIndex]
frame := direction.frames[a.frameIndex]
target.PushTranslation(0, -frame.height)
defer target.Pop()
}

return a.Render(target)
}

func (a *Animation) GetFrameSize(frameIndex int) (int, int, error) {
direction := a.directions[a.directionIndex]
if frameIndex >= len(direction.frames) {
Expand Down

0 comments on commit 418c798

Please sign in to comment.