从 Phaser 3 中的图集创建动画?
Creating animation from atlas in Phaser 3?
我有一个多图集,里面有不同类型的图像:
this.load.multiatlas('images', 'images.json', 'images.png');
我想用图集内的一组特定图像制作动画,比如说,'face1'...'face9'
。创建动画时如何定位它们?我的意思是,有一个方法
this.anims.create({
key: 'faceAnim',
frames: [ {key: '...'}, {key: '...'} ]
})
但我不知道要在 'key' 值中放置什么才能使其正常工作。 key: 'face1'
显然不行,因为Phaser需要知道使用哪个图集。
假设您要使用的所有框架在您的 images.json
文件中都以 face
开头命名,您可以这样做:
this.anims.create({
key: 'images',
frames: this.anims.generateFrameNames('images', { prefix: 'face', start:1, end: 9},
[any other animation config settings you want, repeat, etc.]
});
我在猜测开始值和结束值,因为我看不到您的 images.json
以了解您如何命名所有内容,但这应该让您开始走上正确的道路。 question 也可能有所帮助。
我有一个多图集,里面有不同类型的图像:
this.load.multiatlas('images', 'images.json', 'images.png');
我想用图集内的一组特定图像制作动画,比如说,'face1'...'face9'
。创建动画时如何定位它们?我的意思是,有一个方法
this.anims.create({
key: 'faceAnim',
frames: [ {key: '...'}, {key: '...'} ]
})
但我不知道要在 'key' 值中放置什么才能使其正常工作。 key: 'face1'
显然不行,因为Phaser需要知道使用哪个图集。
假设您要使用的所有框架在您的 images.json
文件中都以 face
开头命名,您可以这样做:
this.anims.create({
key: 'images',
frames: this.anims.generateFrameNames('images', { prefix: 'face', start:1, end: 9},
[any other animation config settings you want, repeat, etc.]
});
我在猜测开始值和结束值,因为我看不到您的 images.json
以了解您如何命名所有内容,但这应该让您开始走上正确的道路。 question 也可能有所帮助。