cocos2d JS 设置字幕循环滚动(背景图滚动亦可)

 
   
 1 var dong = ccs.load("res/Login.json");
 2 this.addChild(dong.node);
 3 
 4 this.cShamNotice = ccui.helper.seekWidgetByName(dong.node,"cShamNotice"); //字幕背景框
 5 this.cShamNotice.setVisible(false);
 6 var str = "请各位玩家文明娱乐,远离赌博。如发现有赌博行为,将封停账号,并向xxxxx举报!诚招各级玩家代理,微信:xxxxxx";
 7 this.tfShamNotice = ccui.helper.seekWidgetByName(dong.node,"tfShamNotice");//文本txt
 8 this.tfShamNotice.setFontName(I18N.defaultFont);
 9 this.tfShamNotice.ignoreContentAdaptWithSize(true);
10 this.tfShamNotice.setString(str);
11 
12 this.runShamNotice(true);
13 
14 
15 
16 //调用此方法计算坐标即可
17 runShamNotice : function(bool) {
18     if(bool) {
19         this.cShamNotice.setVisible(true);
20 
21         var cWidth = this.cShamNotice.getContentSize().width;
22         var cHeight = this.cShamNotice.getContentSize().height;
23         var tfWidth = this.tfShamNotice.getContentSize().width;
24 
25         this.tfShamNotice.setPositionX(cWidth);
26 
27         var runAct = cc.sequence(cc.moveTo(20, -tfWidth, cHeight / 2), cc.callFunc(function() {
28             this.tfShamNotice.setPositionX(cWidth);
29         }, this), cc.delayTime(0.5));
30 
31         this.tfShamNotice.stopAllActions();
32         this.tfShamNotice.runAction(cc.repeatForever(runAct));
33     }else {
34         this.cShamNotice.setVisible(false);
35 
36         this.tfShamNotice.stopAllActions();
37     }
38 }

 

你可能感兴趣的:(cocos2d JS 设置字幕循环滚动(背景图滚动亦可))