cocosCreator动作详解

本文详细介绍了CocosCreator中的动作操作,包括执行动作、移动、旋转、缩放、透明度变化、调用函数、延时、命令清单、循环执行和缓动特效等功能。通过示例代码展示了如何实现组件的各种动画效果,并提供了停止Action的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

动作

组件的移动,旋转、缩放等动画效果称为Action

一个组件可以同时执行多个Action,小明一遍吃蛋糕一遍上厕所

执行动作

runAction

执行动作

this.node.runAction();

移动

moveTo

移动到指定位置

var mto = cc.moveTo(1,cc.v2(100,100));

moveby

移动指定距离

var mby = cc.moveby(1,cc.v2(100,100)); 

旋转

rotateTo

旋转到指定角度

var rto = cc.rotateTo(1,180); //1秒内旋转到180度

rotateBy

旋转指定角度

var rto = cc.rotateBy(1,180); //1秒内旋转180度

缩放

scaleTo

缩放到指定倍数大小

var rto = cc.scaleTo(1,
Cocos Creator模拟砸金蛋3d旋转效果 | 附代码egg.zip // Learn TypeScript: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html // Learn Attribute: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html const {ccclass, property} = cc._decorator; @ccclass export default class Game extends cc.Component { @property Count: number = 5; @property(cc.Prefab) prefab: cc.Prefab = null; @property(cc.Node) nodeParent: cc.Node = null; private mEggs: cc.Node[] = []; // LIFE-CYCLE CALLBACKS: // onLoad () {} start () { } // update (dt) {} onClick(event, data){ switch(data){ case 'add':{ this.addEggs(); break; } case 'move':{ this.moveEggs(); break; } case 'stop':{ this.stopMoveEggs(); break; } } } addEggs(){ if(this.Count <= 0){ return; } this.mEggs = []; const N = 360 / this.Count; for(let i = 0; i < this.Count; i++){ let egg = cc.instantiate(this.prefab); let js = egg.getComponent('Egg'); js.setRadian(i * N * Math.PI / 180); js.updatePos(); egg.parent = this.nodeParent; this.mEggs.push(egg); } } moveEggs(){ for(let i = 0; i < this.mEggs.length; i++){ this.mEggs[i].getComponent('Egg').setMove(true); } } stopMoveEggs(){ for(let i = 0; i < this.mEggs.length; i++){ this.mEggs[i].getComponent('Egg').setMove(false); } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值