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);
復制代碼


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM