Tool.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**工具类 */
  2. export default class Tool {
  3. /**
  4. * 创建按钮节点
  5. * @param style 按钮节点样式
  6. */
  7. public static createButtonNode(style:ButtonNodeStyle):cc.Node{
  8. let node = new cc.Node();
  9. let label = new cc.Node().addComponent(cc.Label);
  10. node.addChild(label.node);
  11. if(style.backgroundImage){
  12. node.addComponent(cc.Sprite).spriteFrame = cc.loader.getRes(style.backgroundImage,cc.SpriteFrame);
  13. }
  14. if(style.transition){
  15. node.addComponent(cc.Button).transition = style.transition
  16. }
  17. if(style.opacity){
  18. node.opacity = style.opacity;
  19. }
  20. if(style.x){
  21. node.x = style.x;
  22. }
  23. if(style.y){
  24. node.y = style.y;
  25. }
  26. if(style.width){
  27. node.width = style.width;
  28. }
  29. if(style.height){
  30. node.height = style.height;
  31. }
  32. if(style.color){
  33. node.color = style.color;
  34. }
  35. if(style.fontColor){
  36. label.node.color = style.fontColor;
  37. }
  38. if(style.fontSize){
  39. label.fontSize = style.fontSize;
  40. }
  41. if(style.lineHeight){
  42. label.lineHeight = style.lineHeight;
  43. }
  44. if(style.content){
  45. label.string = style.content;
  46. }
  47. return node;
  48. }
  49. /**
  50. * 时间格式化
  51. * @param seconds 秒数
  52. */
  53. public static timeFormat(seconds:number):string{
  54. let minute = Math.floor(seconds/60);
  55. let second = Math.floor(seconds%60);
  56. return (minute<10?'0':'')+minute+':'+(second<10?'0':'')+second;
  57. }
  58. }