zoukankan      html  css  js  c++  java
  • 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);
    }
    },
    });
  • 相关阅读:
    OutputCache 缓存key的创建 CreateOutputCachedItemKey
    Asp.net Web Api源码调试
    asp.net mvc源码分析DefaultModelBinder 自定义的普通数据类型的绑定和验证
    Asp.net web Api源码分析HttpParameterBinding
    Asp.net web Api源码分析HttpRequestMessage的创建
    asp.net mvc源码分析ActionResult篇 RazorView.RenderView
    Asp.Net MVC 项目预编译 View
    Asp.net Web.config文件读取路径你真的清楚吗?
    asp.net 动态创建TextBox控件 如何加载状态信息
    asp.net mvc源码分析BeginForm方法 和ClientValidationEnabled 属性
  • 原文地址:https://www.cnblogs.com/kefeiGame/p/7682810.html
Copyright © 2011-2022 走看看