#include "gui/CocosGUI.h"
using namespace gui;
Button* buttonPlay = Button::create();
buttonPlay->setTouchEnabled(true);
buttonPlay->loadTextures("button_play.png", "button_play.png", "");
buttonPlay->setPosition(Point(winSize.width/4, winSize.height/4));
buttonPlay->addTouchEventListener(this, toucheventselector(InGame::ButtentouchEvent));
this->addChild(buttonPlay,PLAYBUTTON,PLAYBUTTON);
void InGame::ButtentouchEvent(Object *pSender, TouchEventType type)
{
Button* butten = (Button*)pSender;
unsigned int tag = butten->getTag();
switch (type)
{
case gui::TOUCH_EVENT_BEGAN:
butten->setPositionY(butten->getPositionY()-10);
break;
case gui::TOUCH_EVENT_MOVED:
break;
case gui::TOUCH_EVENT_ENDED:
butten->setPositionY(butten->getPositionY()+10);
if (tag == PLAYBUTTON)
{
startGame();
}
else
{
}
break;
case gui::TOUCH_EVENT_CANCELED:
butten->setPositionY(butten->getPositionY()+10);
break;
default:
break;
}
}
cocos2dx 使用button控件
最新推荐文章于 2021-07-07 10:31:20 发布