Skip to content

Commit

Permalink
Merge pull request #151 from paolotozzo/fix-animated-sprite
Browse files Browse the repository at this point in the history
Fix animated sprite
  • Loading branch information
inlet committed Oct 17, 2019
2 parents 1b9a013 + ccf7cd5 commit 42bc626
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/components/AnimatedSprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@ import { getTextureFromProps, applyDefaultProps } from '../utils/props'

const AnimatedSprite = (root, props) => {
const { textures, images, autoUpdate, isPlaying = true, initialFrame } = props
const makeTexture = (textures) => {
return textures.map(texture => {
return getTextureFromProps('AnimatedSprite', {
texture,
})
})
}
const animatedSprite = images
? PIXI.AnimatedSprite.fromImages(images)
: new PIXI.AnimatedSprite(
textures.map(texture => {
return getTextureFromProps('AnimatedSprite', {
texture,
})
})
)
: new PIXI.AnimatedSprite(makeTexture(textures))
animatedSprite[isPlaying ? 'gotoAndPlay' : 'gotoAndStop'](initialFrame || 0)
animatedSprite.applyProps = (instance, oldProps, newProps) => {
const { textures, ...props } = newProps
const { isPlaying, initialFrame } = props
applyDefaultProps(instance, oldProps, props)
if(textures) {
instance.textures = makeTexture(textures)
animatedSprite[isPlaying ? 'gotoAndPlay' : 'gotoAndStop'](initialFrame || 0)
}
}

return animatedSprite
Expand Down

0 comments on commit 42bc626

Please sign in to comment.