1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| /** * 创建滚动字幕 * @param txt * @param fontsize * @param {cc.Color|null} color * @param width * @param height * @returns {cc.Node|*} */ createClipRoundText = function(txt,fontsize,color,width,height){ var text = new cc.LabelTTF(txt,"Arial",fontsize); console.log('text width:'+text.width); text.setColor(color?color:cc.color.BLUE); text.anchorX = 0; if(text.width<=width){ text.anchorY = 0; return text; } var cliper = new cc.ClippingNode(); var drawNode = new cc.DrawNode(); drawNode.drawRect(cc.p(0,0),cc.p(width,height),cc.color.WHITE); cliper.setStencil(drawNode); cliper.anchorX = 0.5; cliper.anchorY = 0.5; text.y = height/2; cliper.addChild(text); text.x = width+fontsize; text.runAction(cc.repeatForever(cc.sequence( cc.moveTo(text.width/width*5,cc.p(-text.width,text.y)), cc.callFunc(function(){ text.x = width+fontsize; })))); return cliper; };
|