1. 程式人生 > >GUI動態建立按鈕

GUI動態建立按鈕

#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...");
}