【Cocos2D-X 學習筆記】Node父類的方法和屬性

來源:互聯網
上載者:User

  Node方法:

1、建立節點 Node *childNode=Node::create(); 

     該方法多為Node的子類調用create()靜態方法進行建立執行個體

2、增加新的子節點:node->addChild(childNode,1,Tag); //1是指Z軸的索引,簡單講展示層號,這裡addChild並不是個靜態方法,因此需要進行指標調用,另外根據多態性(函數重載),其形參還可以是 addChild(childNode,int zOrder)  或者addChild(childNode);

3、尋找子節點 Node* node=node->getChildByTag(int Tag);

4、node->removeChildByTag(int Tag,true); 刪除子節點,並停止這些子節點上的一切動作

5、node->removeAllChildrenWithCleanup(true);刪除所有子節點,並停止這些子節點上的一切動作

6、node->removeFromParentAndCleanup(true); 從父Node中刪除該節點自己,並停止所有該節點上的一切動作 

  

  Node中的重要屬性(即成員變數)

1、position

2、anchorPoint (錨點)  anchorPoint是一個相對座標,x,y取值均在(0,1)

     簡單地講就是該錨點在Node對應的矩形中的相對位置

 

  Node中的遊戲迴圈與調度

1、void scheduleUpdate(void) ,每個Node對象只要調用該函數,那麼這個Node對象就會定時地每幀回調用一次自己的update(float dt)函數,注意update函數的float參數不能少;

     對應的如果想停止更新那麼應該調用函數this->unscheduleUpdate(void);方法

2、void schedule(schedule_selector(回到函數指標(函數名)), 重新整理時間t ); 這裡的函數名是update(float)函數

    若要停止重新整理,那麼對應的應使用this->unschedule(schedule_selector(回呼函數名));

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.