| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- // Learn cc.Class:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
- // Learn Attribute:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
- cc.Class({
- extends: cc.Component,
- properties: {
- // foo: {
- // // ATTRIBUTES:
- // default: null, // The default value will be used only when the component attaching
- // // to a node for the first time
- // type: cc.SpriteFrame, // optional, default is typeof default
- // serializable: true, // optional, default is true
- // },
- // bar: {
- // get () {
- // return this._bar;
- // },
- // set (value) {
- // this._bar = value;
- // }
- // },
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this.initView();
- // console.log("预制走这里面吗","onLoad");
- },
- start () {
- // console.log("预制走这里面吗","start");
- },
- initView(){
- this.mymask = UtilsNode.getNode("mymask",this.node);
- //有用的部分
- //头像node
- this.playerHead = UtilsNode.getNode("head",this.mymask);
- //名字node
- this.playerName = UtilsNode.getNode("name",this.node);
- // console.log("预制走这里面吗","initView","this.playerHead",this.playerHead,"this.playerName",this.playerName);
- },
- /**
- let data = {
- headUrl : "",
- name : ""
- }
- * @param data
- */
- setData(data){
- // console.log("预制走这里面吗","setData",this.playerHead,this.playerName);
- this.loadImg(this.playerHead,data.headUrl, data.w, data.h);
- this.setName(this.playerName,data.name);
- },
- setName (node,name){
- node.getComponent(cc.Label).string = name;
- },
- loadImg: function (container, url, w, h) {
- cc.loader.load(url, function (err, texture) {
- var sprite = new cc.SpriteFrame(texture);
- container.getComponent(cc.Sprite).spriteFrame = sprite;
- if (w != null) {
- container.width = w;
- }
- if (h != null) {
- container.height = h;
- }
- });
- },
- // update (dt) {},
- });
|