cocos2d-js动作模块使用(自用,只有代码)
Posted KefeiGame
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cocos2d-js动作模块使用(自用,只有代码)相关的知识,希望对你有一定的参考价值。
// var UIBase = require("src/views/ui/UIBase.js")
// cc.loader.loadJs("src/views/ui/UIBase.js")
var LuckDrawUI = UIBase.extend({
ctor: function () {
this._super();
this.resourceFilename = "res/ui/LuckDrawUI.json";
this._initPosition = 1; //初始位置
this._Chance = [0.1,0.2,0.3,0.4,0.5,0.6,0.8,1];
this._ChanceId = 0;
this._prize_panel = undefined; //奖品容器
this._prize_img = undefined; //当前奖品
this._prize_btn = undefined;
},
initUI: function () {
cutil.unlock_ui();
this.luckdraw_panel = this.rootUINode.getChildByName("luckdraw_panel");
var self = this;
this.preClick();
//
this.luckdraw_panel.getChildByName("back_btn").addTouchEventListener(function (sender, eventType) {
if (eventType == ccui.Widget.TOUCH_ENDED) {
self.hide();
}
});
this._prize_btn=ccui.helper.seekWidgetByName(self.luckdraw_panel, "click_btn")
this._prize_btn.addTouchEventListener(function (sender,eventType){
if (eventType == ccui.Widget.TOUCH_ENDED) {
self.runNoEffect(0,0,0,0);
}
});
},
winChance:function(){
var self = this;
var id = Math.random();
cc.log("id = "+id.toString())
for (var i = 1; i < 8;i++)
{
if (id <= self._Chance[0])
{
self._ChanceId = 1;
}else
{
if (id <= self._Chance[i] && id > self._Chance[i-1])
{
self._ChanceId = i+1;
break;
}
}
}
cc.log("chanceID = "+ self._ChanceId.toString())
},
//转动效果无实际用处
runNoEffect:function(total,first,second,third) {
var self = this;
self._prize_btn.setEnabled(false);
self.winChance();
var callback_start = cc.callFunc(function () {
self._prize_img.setVisible(false);
if (self._initPosition < 8)
{
self._initPosition++;
}else
{
self._initPosition = 1;
}
self._prize_img=ccui.helper.seekWidgetByName(self.luckdraw_panel, "prize_flaring_img_"+self._initPosition.toString());
self._prize_img.setVisible(true);
});
var callback_prize = cc.callFunc(function (target, data) {
self._prize_img.setVisible(false);
cc.log("前"+self._initPosition.toString())
cc.log(data[0].toString)
if (self._initPosition < data[0])
{
self._initPosition++;
}
cc.log("后"+self._initPosition.toString())
self._prize_img=ccui.helper.seekWidgetByName(self.luckdraw_panel, "prize_flaring_img_"+self._initPosition.toString());
self._prize_img.setVisible(true);
},this,[self._ChanceId]);
//抽奖结果
var callback_result = cc.callFunc(function()
{
self._prize_btn.setEnabled(true);
});
var numFirst = 0;
if (8-self._initPosition <= 0)
numFirst = 1;
else
numFirst = 8-self._initPosition;
var runFirst = cc.sequence(cc.delayTime(0.2),callback_start).repeat(numFirst+1);
var runSecond = cc.sequence(cc.delayTime(0.05),callback_start).repeat(32);
var runThird = cc.sequence(cc.delayTime(0.2),callback_start).repeat(8);
var runForth = cc.sequence(cc.delayTime(0.4),callback_prize).repeat(self._ChanceId);
self.luckdraw_panel.runAction(cc.sequence(runFirst,runSecond,runThird,runForth,callback_result));
},
//
preClick: function () {
var self = this;
self._prize_panel=this.luckdraw_panel.getChildByName("prize_panel_"+self._initPosition.toString());
cc.log(self._prize_panel.toString())
self._prize_img = self._prize_panel.getChildByName("prize_flaring_img_"+self._initPosition.toString());
cc.log(self._prize_img.toString())
if(!self._prize_img.isVisible())
{
self._prize_img.setVisible(true);
}
},
});
以上是关于cocos2d-js动作模块使用(自用,只有代码)的主要内容,如果未能解决你的问题,请参考以下文章