hi,
I am leaning CC, I am more interested write code than using tool CC, but that is not working.
I am using CC version 3.8.1
this is images of 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) => {
res(texture);
});
})
}
let createAnimationArray = async(parent, list: any, speed:number = 0.1, loop: boolean = false, path:string = 'int04') => {
return new Promise(async (res,fai) => {
let arr = [];
let pro = [];
for(let i = 0; i < list.length; i++) {
pro.push(spriteFrame(list[i], path));
}
let data = await Promise.all(pro);
for(let i = 0; i < data.length; i++) {
arr.push(data[i]);
}
let node = new Node();
node.addComponent(Sprite);
let animation = node.addComponent(Animation);
let clip = AnimationClip.createWithSpriteFrames(arr, 10);
clip.wrapMode = loop ? AnimationClip.WrapMode.Loop : AnimationClip.WrapMode.Normal;
clip.speed = speed;
animation.addClip(clip);
animation.play(clip.name);
animation.playOnLoad = true;
parent.addChild(node);
res(node)
});
}
let spriteFrame = async(name: string, path:string = 'int04') => {
return new Promise(async (res,fai) => {
let texture = await getImg(name, path);
const node = new Node();
const spriteFrame = new SpriteFrame();
const tex = texture;
spriteFrame.texture = tex;
const sprite = node.addComponent(Sprite);
sprite.spriteFrame = spriteFrame;
res(node)
})
}
let bien = new cc.Node();
bien.addComponent(cc.Graphics);
let bien_troi = int04.createAnimationArray(bien,['23020_0_8', '23020_0_9', '23023_3_6'], 0.1, true, 'map/dat');
That is created in node, but it not show in screen, (this is images of node, but is not working):
Thank.