创建“继续”按钮:
auto stopButton=Button::create("stop.png");//创建暂停按钮
stopButton->setPosition(Vec2(_screenWidth-32,_screenHeight-32));
stopButton->setZOrder(100);
stopButton->setScale(3);
stopButton->addTouchEventListener([=](Ref* pSender,Widget::TouchEventType type){//添加“暂停”按钮监听事件
Director::sharedDirector()->pause();//停止
if(type==Widget::TouchEventType::ENDED)
{
auto cont=Button::create("button.png");
cont->setTitleText("Go On");
cont->setScale(2);
cont->setTitleFontSize(16);
cont->setPosition(Vec2(_screenWidth/2,_screenHeight*0.6));
this->addChild(cont,1);
cont->addTouchEventListener([=](Ref* pSender,Widget::TouchEventType type){
if(Widget::TouchEventType::ENDED==type)
{
Director::sharedDirector()->resume();//继续暂停前的动作
this->removeChild(cont);//移除“继续”按钮
}
});
});