Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88817

cocosCreator用cc.AnimationClip代码创建的动画,怎么设定关键帧事件

$
0
0

@shilong1028 写道:

今天用代码创建帧动画,想播放一定时间或帧数后,结束。发现关键帧事件没有触发。寻求大牛帮助。
附上代码:
frameEvent: function(params){
cc.log("aniFrameEvent(), params = "+JSON.stringify(params))
},

onLoad () {
	this.addTouchEvent();
	
	var frameEvent1 = function(params){
		cc.log("aniFrameEvent(), params = "+JSON.stringify(params))
	};
	
	var animation = this.aniNode.getComponent(cc.Animation);
    
    cc.loader.loadRes("aniAtlas/baoji", cc.SpriteAtlas, (err, atlas) => {
        var spriteFrames = atlas.getSpriteFrames();
        
		//cc.AnimationClip动画剪辑,用于存储动画数据。
        var clip = cc.AnimationClip.createWithSpriteFrames(spriteFrames, 4);   //createWithSpriteFrames(spriteFrames, Num) 使用一组序列帧图片来创建动画剪辑
        clip.name = 'baoji';
		clip.speed = 1.1;   //播放速度,值越大速度越快,值越小则速度越慢
        clip.wrapMode = cc.WrapMode.Loop;   // 设置循环模式为 Loop 或 Normal,Normal 类型repeatCount 将被设置为 1,Loop 类型repeatCount 将被设置为 Infinity
		//clip.repeatCount = 2;  //设置动画循环次数为2次,Infinity设置动画循环次数为无限次
			
		//* 添加关键帧事件 
		clip.events.push(
			{frame:0, func: 'frameEvent', params: ['par_1', 'par_2']},
			{
				frame: 2,                   // 准确的时间,以秒为单位。这里表示将在动画播放到 5s 时触发事件
				func: 'frameEvent',         // 回调函数名称
				params: [2, 'two_second']        // 回调参数
			});
		//*/

        animation.addClip(clip);
        animation.play('baoji');  
        });
},

帖子: 1

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88817

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>