| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- /**工具类 */
- export default class Tool {
- /**
- * 创建按钮节点
- * @param style 按钮节点样式
- */
- public static createButtonNode(style:ButtonNodeStyle):cc.Node{
- let node = new cc.Node();
- let label = new cc.Node().addComponent(cc.Label);
- node.addChild(label.node);
- if(style.backgroundImage){
- node.addComponent(cc.Sprite).spriteFrame = cc.loader.getRes(style.backgroundImage,cc.SpriteFrame);
- }
- if(style.transition){
- node.addComponent(cc.Button).transition = style.transition
- }
- if(style.opacity){
- node.opacity = style.opacity;
- }
- if(style.x){
- node.x = style.x;
- }
- if(style.y){
- node.y = style.y;
- }
- if(style.width){
- node.width = style.width;
- }
- if(style.height){
- node.height = style.height;
- }
- if(style.color){
- node.color = style.color;
- }
- if(style.fontColor){
- label.node.color = style.fontColor;
- }
- if(style.fontSize){
- label.fontSize = style.fontSize;
- }
- if(style.lineHeight){
- label.lineHeight = style.lineHeight;
- }
- if(style.content){
- label.string = style.content;
- }
- return node;
- }
- /**
- * 时间格式化
- * @param seconds 秒数
- */
- public static timeFormat(seconds:number):string{
- let minute = Math.floor(seconds/60);
- let second = Math.floor(seconds%60);
- return (minute<10?'0':'')+minute+':'+(second<10?'0':'')+second;
- }
- }
|