#include "cocos2d.h" #include "cocos-ext.h" USING_NS_CC; USING_NS_CC_EXT; using namespace ui; UIButton *button = UIButton::create(); button->setTouchEnabled(true); button->loadTextures("close1.png", "close2.png",""); //按钮纹理 button->setPosition(ccp(visibleSize.width/2, visibleSize.height/2)); button->addTouchEventListener(this, toucheventselector(HelloWorld::touchEvent));//按钮的事件 m_pUiLayer = UILayer::create(); //创建一个UI层 m_pUiLayer->addWidget(button);//加入画布 this->addChild(m_pUiLayer); void HelloWorld::touchEvent(CCObject *pSender, TouchEventType type) { CCLOG("test..."); }
GUI动态创建button
时间: 2024-10-13 12:13:30