简简单单一个序列帧动画,死活播放不了。大佬帮我看看。

  • Creator 版本:3.8.3

  • 目标平台: chrome

import { _decorator, Component, Node, Animation, Sprite, AnimationClip,SpriteAtlas,math } from ‘cc’;

const { ccclass, property } = _decorator;

@ccclass(‘NewComponent’)

export class NewComponent extends Component {

@property(SpriteAtlas)

private frames: SpriteAtlas;

start() {

    let node = new Node();

    node.setScale(new math.Vec3(2, 2, 1))

    let sp = node.addComponent(Sprite)

    sp.spriteFrame = this.frames.getSpriteFrame("buff_arrow_7");

    let animation = node.addComponent(Animation);

    let animationClip = AnimationClip.createWithSpriteFrames(this.frames.getSpriteFrames(), 5);

    // animation.clips.push(animationClip);

    animation.addClip(animationClip);

    // animation.playOnLoad = true;

    animationClip.wrapMode = AnimationClip.WrapMode.Loop;

    // animationClip.speed = 1

    // animation.defaultClip = animationClip

    // animationClip.name = "test"

    animation.play();

    this.node.addChild(node);

}

update(deltaTime: number) {

   

}

}

代码如上。能显示一个静态图片,就是不播放动画。各种属性和方法都试了,播不出来。大佬给看看。

项目工程 项目.zip (27.3 KB)

可以试一下

可以。感谢大佬。
总结一下,问题出在animation.play()方法调用必须在this.node.addChild(node);之后调用才有效。或者设置animation.playOnLoad = true;不调用animation.play();