-
Notifications
You must be signed in to change notification settings - Fork 0
SpriteSheet
何波 edited this page Feb 23, 2019
·
9 revisions
var data = {
images: ["sprites.jpg"],
images: [this.game.load.get('ship')]],
frames: {width:50, height:50},
frames: {width:64, height:64, count:20, regX: 32, regY:64, spacing:0, margin:0},
frames: [
// x, y, width, height, imageIndex*, regX*, regY*
[64, 0, 96, 64],
[0, 0, 64, 64, 1, 32, 32]
// etc.
],
animations: {
// start, end, next*, speed*
run: [0, 8],
jump: [9, 12, "run", 2]
},
animations: {
stand:0,
run:[1,5],
jump:[6,8,"run"]
},
animations: {
walk: {
frames: [1,2,3,3,2,1]
},
shoot: {
frames: [1,4,5,6],
next: "walk",
speed: 0.5
}
}
};
var spriteSheet = new createjs.SpriteSheet(data);
var animation = new createjs.Sprite(spriteSheet, "run");在用Animate CC制作一个MovieClip元件时,可以Edit Multiple Frames,再Ctrl+A全选所有桢拖动元件到“+”号位置来改变Movie Clip的中心点(一般我们拖动“+”号到MC中心)。在Libray中,右键选中此Movie Clip从右键菜单中选择“Generate Sprite Sheet”,导出的Data数据会带上regX,regY。
export default class Ship {
constructor (game) {
this.game = game
this.init()
}
init () {
let data = {
images: [this.game.load.get('ship')],
frames: [
// x, y, width, height, imageIndex*, regX*, regY*
// fly,die,bubble动画所有帧的中心点都在图片的中央,如果用Sprite来设置中心点,是很难分别设各animations的regX,regY的
[0, 0, 82, 60, 0, 41, 30],
[0, 60, 130, 130, 0, 65, 65],
[0, 190, 130, 130, 0, 65, 65],
[0, 320, 130, 130, 0, 65, 65],
[0, 450, 170, 170, 0, 86, 88]
],
framerate: 5,
animations: {
fly: [0],
die: [1, 3],
bubble: [4]
}
}
let spriteSheet = new createjs.SpriteSheet(data)
this.sprite = new createjs.Sprite(spriteSheet)
this.game.stage.addChild(this.sprite)
this.sprite.set({ x: this.game.canvas.width / 2, y: this.game.canvas.height / 2 })
console.info(this.sprite.regX) // sprite的regX还是为0
this.sprite.gotoAndPlay('fly')
}
}