cocos2d-X 节点(UILayer.h)API

本文详细介绍了cocos2d-X中节点类UILayer.h的API使用,包括如何获取UIInputManager,添加/移除Widget以及设置UILayer的可见性。此外,建议读者参考作者的Cocos2d-X权威指南笔记以获得更全面的学习资料。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文来自http://blog.youkuaiyun.com/runaying ,引用必须注明出处!

cocos2d-X 节点(UILayer.h)API

温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记

获取 UIInputManager,添加/移除 widget,设置 UILayer 的可见

/////cocos2d-x-3.0alpha0/extensions/CocoStudio/GUI/System
// 获取 UIInputManager,添加/移除 widget ,设置 UILayer 的可见 性


#ifndef __UILAYER_H__
#define __UILAYER_H__

#include "cocos2d.h"
#include "ExtensionMacros.h"
#include "../BaseClasses/UIRootWidget.h"
#include "../System/UIInputManager.h"

NS_CC_EXT_BEGIN


class UILayer : public Layer
{
    
public:
    /**
     * Default constructor
     */
    UILayer();
    
    /**
     * Default destructor
     */
    virtual ~UILayer();
    
    /**
     * Allocates and initializes a widget.
     */
    static UILayer *create(void);
    
    //initializes state of uilayer.         //初始化 uilayer 的状态
    virtual bool init();
    
    virtual void onEnter();
    virtual void onExit();
    virtual void onEnterTransitionDidFinish();
    
    virtual bool onTouchBegan(Touch *pTouch, Event *pEvent);
    virtual void onTouchMoved(Touch *pTouch, Event *pEvent);
    virtual void onTouchEnded(Touch *pTouch, Event *pEvent);
    virtual void onTouchCancelled(Touch *pTouch, Event *pEvent);
    
    /**
     * Add a widget to UILayer, for drawing.                //为绘制添加一个 eidget 到 UILayer
     *
     * @param widget.
     */
    void addWidget(UIWidget* widget);
    
    /**
     * Remove a widget from UILayer.
     *
     * @param widget.
     *
     * @param cleanup true 所有 children widgets 运行的 所有 action 都将 删除, false otherwise.
     */
    void removeWidget(UIWidget* widget);
    
    /**
     * Sets whether the UILayer is visible                          可见
     *
     * 默认值是 true ,默认可见
     *
     * @param visible   true if the UILayer is visible, false if the UILayer is hidden.
     */
    virtual void setVisible(bool visible);
    
    /**
     * Finds a widget whose tag is equal tag param from widget tree.        //从 widget 树上查找 tag 等于输入参数的 widget
     *
     * @param tag.
     */
    UIWidget* getWidgetByTag(int tag);
    
    /**
     * Seek a widget whose name is equal name param from widget tree.       //从 widget 树上查找 name 等于输入参数的 widget
     *
     * @param name.
     */
    UIWidget* getWidgetByName(const char* name);
    
    /**
     * Gets UIInputManager.
     *
     * UIInputManager 管理 UILayer 的触摸.
     *
     * @return UIInputManager.
     */
    UIInputManager* getInputManager();
    
    /**
     * Remove and clean up all of UILayer's widget.             //移除并清理所有的  UILayer's widget.
     */
    virtual void clear();
    
    /**
     * Gets root widget of UILayer.
     *
     * @return UIRootWidget, "UIRootWidget" is the root widget of UILayer.
     */
    UIRootWidget* getRootWidget();
    
protected:
    UIRootWidget* _rootWidget;
    UIInputManager* _inputManager;
};

NS_CC_EXT_END



#endif /* defined(__UILAYER_H__) */


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值