-
Notifications
You must be signed in to change notification settings - Fork 327
Closed
Description
spritejs很赞,不过我在使用中遇到了一个问题block住了开发,求助~
预期目标:在每次点击【点击播放】按钮时,都能够完整执行一次切换texture的动画
问题描述:仅首次点击后可以正常执行动画,但是此后的点击不再渲染动画
简化的case:
class App extends Component {
constructor() {
super();
this.sprite = null;
this.onPlay = this.onPlay.bind(this);
}
componentDidMount() {
this.init();
}
/**
* 初始化动画
*/
init = () => {
const scene = new Scene('#container', {
viewport: ['auto', 'auto'],
resolution: [750, 1254],
});
const layer = this.layer = scene.layer();
this.sprite = new Sprite();
this.sprite.attr({ anchor: [0, 0], pos: [0, 0], size: [750, 1254], });
layer.append(this.sprite);
}
/**
* 播放动画
*/
async onPlay() {
// 事先缓存的img列表,试图通过切换图片播放一组动画
const { imgs } = this.props;
// 纹理贴图
const keyframes = imgs.map((item) => { return { textures: item } });
// 播放配置项
const option = { duration: 3000, iterations: 1, easing: 'linear', fill: 'both' }
// 执行动画
await this.sprite.animate(keyframes, option).finished;
}
render() {
return (
<div className="animation-btn" onClick={this.onPlay}>【点击播放】</div>
)
}
}
Metadata
Metadata
Assignees
Labels
No labels