cocos creator(11)

1.动作系统

cocos里自带的封装好的系统
延时动作*


const {ccclass, property} = cc._decorator;

@ccclass
export default class NewScript extends cc.Component {

    @property(cc.Label)
    label: cc.Label = null;

    @property
    text: string = 'hello';


    start () {
        //动作
        //移动
        let action = cc.moveTo(2,cc.v2(200,200));//(运动时间,运动目标位置)位置也可以直接打坐标
        action = cc.moveBy(2,200,200);//以自己为原点移动输入的距离
        
        //旋转
        action = cc.rotateTo(2,100);

        //缩放
        action = cc.scaleTo(2,2);//一个数整体缩放 两个数xy方向缩放

        //跳跃
        action = cc.jumpBy(2,200,0,100,1);//秒,x,y,高度,跳几次

        //闪烁
        action = cc.blink(3,5);//三秒闪烁五次

        //淡出
        action = cc.fadeOut(3);
        //淡入
        action =cc.fadeIn(3);
        //渐变
        action = cc.fadeTo(3,100);

        //颜色
        action = cc.tintTo(3,100,30,100);//(秒,rgb)

        //执行动作
        this.node.runAction(action);
        //停止动作
        this.node.stopAction(action);//停止某个动作,括号内输入动作值
        this.node.stopAllActions();//停止所有动作

        //设置动作tag值
        action.setTag(1);
        //通过tag值暂停
        this.node.stopActionByTag(1);//通过tag来停止动作
    
        //暂停
        this.node.pauseAllActions();
        //恢复
        this.node.resumeAllActions();
    }

   

2.容器动作

瞬时动作

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewScript extends cc.Component {

    @property(cc.Label)
    label: cc.Label = null;

    @property
    text: string = 'hello';

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start () {
        //动作
        //立刻显示
        let action = cc.show();
        //立刻隐藏
        action =cc.hide();
        //切换显示隐藏
        action = cc.toggleVisibility();

        //反转
        action = cc.flipX(true); //X轴翻转
        action = cc.flipY(true); //Y轴翻转
        
        //回调
        action = cc.callFunc(()=>{

        //执行一系列动作/队列
        let action1 = cc.fadeOut(1);
        let action2 = cc.fadeIn(1);
        //容器动作
        let seq = cc.sequence(action1,action2);
        let seq1 = cc.sequence(action1,action2,cc.callFunc(()=>{ //执行完两个动作后再回调

        }));
        //重复动作
        let repeat = cc.repeat(seq,3);//(重复动作,次数)
        repeat = cc.repeatForever(seq);//一直重复
        
        //并列动作
        let move = cc.moveTo(3,100,100);
        let color = cc.tintTo(3,100,100,20);
        let spawn = cc.spawn(move,color);//move和color并行执行
        
        this.node.runAction(seq);
        });
    
    }

    // update (dt) {}
}

3.动画系统

添加组件—>其他组件—>Animation
在这里插入图片描述
双击属性列表里的属性进入对动作速度的修改在这里插入图片描述

添加人物动画
添加人物动画,在属性列表 Add Property中点击cc.Sprite.spriteFrame再把一组图片拉到对应帧 需要循环设置为loop
在这里插入图片描述
一般速度调为12帧每秒

// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewScript extends cc.Component {

    @property(cc.Label)
    label: cc.Label = null;

    @property
    text: string = 'hello';

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start () {
        //获取动画组件
        let ani = this.getComponent(cc.Animation);    
        
        //播放动画
        ani.play("bird");

        //暂停播放
        ani.pause("bird");

        //恢复播放
        ani.resume("bird");

        //停止播放
        ani.stop("bird");
    }
    
    

    // update (dt) {}
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值