label.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Learn cc.Class:
  2. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. // foo: {
  14. // // ATTRIBUTES:
  15. // default: null, // The default value will be used only when the component attaching
  16. // // to a node for the first time
  17. // type: cc.SpriteFrame, // optional, default is typeof default
  18. // serializable: true, // optional, default is true
  19. // },
  20. // bar: {
  21. // get () {
  22. // return this._bar;
  23. // },
  24. // set (value) {
  25. // this._bar = value;
  26. // }
  27. // },
  28. },
  29. // LIFE-CYCLE CALLBACKS:
  30. // onLoad () {},
  31. start () {
  32. let node = this.node;
  33. // node.x = 100;
  34. node.x = -10;
  35. //获取组件
  36. let label = this.getComponent(cc.Label);
  37. //修改显示的字符串
  38. let text = this.name + 'started';
  39. //显示字符串
  40. // label.string = text;
  41. label.string = "学习Cocos";
  42. },
  43. // update (dt) {},
  44. });