hi,
If anyone knows about animationClip, please let me know.
I am creating a function used to create animationClips passing in image parameters.
My code works, but I’m having problems, even though I updated its size to 48x48 (the images for animation are 96x96).
When exported to the screen, it displayed 48x48, no problem at all. However, when I start animationClip, its size returns to 96x96.
So how do I turn off this auto-change mode, or make this attribute default to the parent NODE.
Here is my code:
let getImg = async (name : string, path : string = 'int04') => {
return new Promise((res,fai) => {
cc.resources.load(path+"/"+name+"/spriteFrame", cc.spriteFrame ,(err, texture) => {
// change size
res(texture);
});
})
}
let createAnimationArray = async(parent, list: any, speed:number = 0.1, loop: boolean = true, path:string = 'int04') => {
return new Promise(async (res,fai) => {
let arr = [];
let pro = [];
for(let i = 0; i < list.length; i++) {
pro.push(getImg(list[i], path));
}
let data = await Promise.all(pro);
for(let i = 0; i < data.length; i++) {
let texture = data[i];
// create a new spriteFrame with texture and change size 48x48
let spriteFrame = new SpriteFrame();
spriteFrame.texture = texture;
arr.push(spriteFrame);
}
let node = new Node();
node.addComponent(cc.Sprite);
parent.addChild(node);
node.getComponent(cc.Sprite).spriteFrame = arr[0];
node.getComponent(UITransform).width = 48;
node.getComponent(UITransform).height = 48;
let animation = node.addComponent(Animation);
let clip = AnimationClip.createWithSpriteFrames(arr, 60);
clip.wrapMode = loop ? AnimationClip.WrapMode.Loop : AnimationClip.WrapMode.Normal;
clip.speed = speed;
clip.name = 'animationc';
animation.addClip(clip, clip.name);
animation.play(clip.name);
animation.playOnLoad = true;
res(node)
});
}
Thank you very much.