帧动画
优质
小牛编辑
125浏览
2023-12-01
帧动画模块可以将一系列BK.TextureInfo对象进行播放,构成动画效果。
父类:BK.Sprite
构造函数 BK.AnimationSprite(textureInfoArray)
通过textureInfoArray数组创建一个帧动画对象
手Q版本:7.6.3
textureInfoArray:
参数名 | 类型 |
---|---|
textureInfoArray | Array |
BK.TextureInfo可以通过图集生成获得。
setSize(Object)
设置动画大小
手Q版本:7.6.3
Object参数:
属性名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
width | number | 是 | 宽度,单位:像素 |
height | number | 是 | 高度,单位:像素 |
setAnchor(Object)
设置锚点,不进行设置默认为{x:0,y:0},即图片左下角。
手Q版本:7.6.3
Object参数:
属性名 | 类型 | 是否必填 |
---|---|---|
x | number | 是 |
y | number | 是 |
setPosition(Object)
设置位置,不进行设置默认为{x:0,y:0}
手Q版本:7.6.3
Object参数:
属性名 | 类型 | 是否必填 |
---|---|---|
x | number | 是 |
y | number | 是 |
setFrameDuration(duration)
设置每一帧的时长,默认为1/30秒。
手Q版本:7.6.3
6. play(Object)
播放帧动画,可通过stop()停止,pause()暂停,repeatCount次数达到后自动停止
手Q版本:7.6.3
Object参数:
属性名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
beginFrameIndex | number | 否 | 开始播放帧的下标。默认从第0帧开始播放 |
repeatCount | number | 否 | 播放次数。默认为-1,即无限次播放 |
pause()
暂停帧动画,可通过 resume()恢复
手Q版本:7.6.3
resume()
继续播放通过pause()暂停的帧动画
手Q版本:7.6.3
stop()
停止播放帧动画
手Q版本:7.6.3
setCompleteCallback(Function(obj))
设置播放完成一次的回调,播放多次会回调多次。
手Q版本:7.6.3
obj成员
属性名 | 类型 | 说明 |
---|---|---|
animationSprite | AnimationSprite | 当前帧动画对象 |
count | number | 已经播放的次数 |
setEndCallback(Function(obj))
设置播放结束的回调,只会在最终停止的时候回调。
手Q版本:7.6.3
obj成员
属性名 | 类型 | 说明 |
---|---|---|
animationSprite | AnimationSprite | 当前帧动画对象 |
count | number | 已经播放的次数 |
示例:
var texPath = "GameRes://fighter.png";
var jsonPath = "GameRes://fighter.json";
BK.SpriteSetCache.loadSet({jsonPath:jsonPath, texturePath:texPath});
var textureInfoArr = new Array();
for (var i = 0; i < 30; i++) {
var val = i < 10 ? '0' + i : i;
var textureInfo = BK.SpriteSetCache.getTextureInfoByFilename('rollSequence00' + val + '.png');
textureInfoArr.push(textureInfo);
}
var aniSp = new BK.AnimationSprite(textureInfoArr);
//设置锚点
aniSp.setAnchor({ x: 0.5, y: 0.5 });
//设置大小
aniSp.setSize({ width: 175 * 2, height: 240 * 2 });
var scrSize = BK.Director.screenPixelSize;
//设置坐标
aniSp.setPosition({ x: scrSize.width / 2.0, y: scrSize.height / 2.0 });
BK.Director.root.addChild(aniSp);
//设置每一帧持续时间,以秒为单位。默认1/30秒
aniSp.setFrameDuration(1/60);
//开始播放
aniSp.play({beginFrameIndex:0,repeatCount:50});
//播放完一次的回调
aniSp.setCompleteCallback(function (animationInfo) {
BK.Script.log(0,0,"setCompleteCallback count:"+animationInfo.count);
});
//全部播放完的回调
aniSp.setEndCallback(function (animationInfo) {
BK.Script.log(0,0,"setEndCallback count:"+animationInfo.count);
});
//暂停
function pause(){
aniSp.pause();
}
//恢复
function resume(){
aniSp.resume();
}
//停止
function stop(){
aniSp.stop();
aniSp.dispose();//销毁
}