Cocos Creator 获取节点的方式

1.通过find方式获取
//获取节点 var node=cc.find("Canvas/logo"); //获取精灵组件 var sprite=node.getComponent(cc.Sprite);


2.通过在构造函数中定义组件,并且从层级管理器中拉入节点。
cc.Class({
    extends: cc.Component,
    properties: {
        label: {
            default: null,
            type: cc.Label
        },
        logo: {
            default: null,
            type: cc.Sprite
        },
    }

//代码中访问组件
self.logo.spriteFrame = new cc.SpriteFrame(img);
复制代码
原文地址:https://www.cnblogs.com/luorende/p/7589195.html