head.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/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. this.initView();
  32. // console.log("预制走这里面吗","onLoad");
  33. },
  34. start () {
  35. // console.log("预制走这里面吗","start");
  36. },
  37. initView(){
  38. this.mymask = UtilsNode.getNode("mymask",this.node);
  39. //有用的部分
  40. //头像node
  41. this.playerHead = UtilsNode.getNode("head",this.mymask);
  42. //名字node
  43. this.playerName = UtilsNode.getNode("name",this.node);
  44. // console.log("预制走这里面吗","initView","this.playerHead",this.playerHead,"this.playerName",this.playerName);
  45. },
  46. /**
  47. let data = {
  48. headUrl : "",
  49. name : ""
  50. }
  51. * @param data
  52. */
  53. setData(data){
  54. // console.log("预制走这里面吗","setData",this.playerHead,this.playerName);
  55. this.loadImg(this.playerHead,data.headUrl, data.w, data.h);
  56. this.setName(this.playerName,data.name);
  57. },
  58. setName (node,name){
  59. node.getComponent(cc.Label).string = name;
  60. },
  61. loadImg: function (container, url, w, h) {
  62. cc.loader.load(url, function (err, texture) {
  63. var sprite = new cc.SpriteFrame(texture);
  64. container.getComponent(cc.Sprite).spriteFrame = sprite;
  65. if (w != null) {
  66. container.width = w;
  67. }
  68. if (h != null) {
  69. container.height = h;
  70. }
  71. });
  72. },
  73. // update (dt) {},
  74. });