Skip to content

Commit

Permalink
fix issue with updating animated sprite texture
Browse files Browse the repository at this point in the history
  • Loading branch information
Paolo Tozzo committed Oct 17, 2019
1 parent 9f7a180 commit ccf7cd5
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 ccf7cd5

Please sign in to comment.