cocosjs做了1年多。ccs1.6和cocosjs3.1的坑该趟的都趟了。手上的项目快上线。今天把项目中遇到的一些效果,在这里说说。
1.最常见的,莫过于这种新邮件提示了,就是让图标不停的晃动。
代码:
mailBtn.runAction(cc.repeatForever(cc.sequence(
cc.repeat(cc.sequence(
cc.rotateBy(0.1,10),
cc.rotateBy(0.2,-10)
),4),
cc.callFunc(function(){this.setRotation(0);},mailBtn),
cc.delayTime(0.3)
)));2.还有就是这种闪光效果了,原理很简单,2张图,A不带光,B带光,A置于B上层,B做淡入淡出 <img title = '闪光.gif' src='http://cdn.cocimg.com/bbs/attachment/Fid_59/59_299331_99cd0ec32243782.gif' > <pre class="brush:js; toolbar: true; auto-links: false;"> B.runAction(cc.repeatForever(cc.sequence( cc.fadeOut(0.8), cc.fadeIn(0.8) )));
3.模仿雷霆战机的按钮。做那种放大淡出特效
var shineBtn = ccui.helper.seekWidgetByName(self.content, id2name*); var tempBtn = shineBtn.clone(); //采用的是ccui,所以可以直接clone tempBtn.setTouchEnabled(false); tempBtn.setPosition(shineBtn.width/2,shineBtn.height/2); tempBtn.runAction(cc.sequence( cc.repeat(cc.sequence( cc.spawn(cc.scaleTo(1,1.3).easing(cc.easeIn(3)),cc.fadeOut(1)), cc.callFunc(function(){tempBtn.setScale(1);tempBtn.setOpacity(255);},tempBtn), cc.delayTime(0.3) ),10), cc.callFunc(function(){this.removeFromParent(true);},tempBtn) )); shineBtn.addChild(tempBtn, 11); ``` 4.顺序播放多对象动画var action = cc.repeatForever(cc.spawn( cc.targetedAction(self.fonts, cc.sequence(cc.moveBy(0.1,cc.p(0,20)), cc.moveBy(0.1,cc.p(0,-20)))), cc.targetedAction(self.fonts, cc.sequence(cc.delayTime(0.1),cc.moveBy(0.1,cc.p(0,20)), cc.moveBy(0.1,cc.p(0,-20)))), cc.targetedAction(self.fonts, cc.sequence(cc.delayTime(0.2),cc.moveBy(0.1,cc.p(0,20)), cc.moveBy(0.1,cc.p(0,-20)))), cc.targetedAction(self.fonts, cc.sequence(cc.delayTime(0.3),cc.moveBy(0.1,cc.p(0,20)), cc.moveBy(0.1,cc.p(0,-20)))) )); fightShowLayer.runAction(action); ``` 5.抽奖this.selectid = 0; //最终位置id this.VO = 0.01; //初始速度 this.totalTime = 0; //计步 this.GA = 0.1; //加速度 this.isMoving = false; //是否已经开始转动(防止多次启动抽奖动画) this.scheduleUpdate(); //开启update update:function(dt){ this.VO += this.GA*dt; //减速运动 this.totalTime += dt; if(this.totalTime > this.VO) { this.totalTime -= this.VO; if(++this.selectid == 17) this.selectid = 0; this.selectrect.setPosition(this.lotterylayer.getChildByName("item1_"+this.selectid)); } if(this.VO >= 0.3) {this.VO = 0.3;} if(this.VO >= 0.3 && this.selectid == this.toID){ this.isMoving = false; this.unscheduleUpdate(); } }, ``` 6.倒计时this.cdtime= 100; this.totalTime = 0; //计步 this.scheduleUpdate(); //开启update update:function(dt){ this.totalTime += dt; if(this.totalTime > 1) { this.totalTime -= 1; this.cdtime -= 1 cdText.setString(this.cdtime+"秒"); //cdText为text控件 } }, ``` *