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);
Cocos Creator 获取节点的方式

相关文章:

  • 2018-03-25
  • 2022-12-23
  • 2021-08-22
  • 2021-11-21
  • 2021-11-16
  • 2021-07-27
  • 2021-04-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-18
  • 2021-11-24
  • 2022-12-23
  • 2022-12-23
  • 2021-08-31
相关资源
相似解决方案