Im wondering if it’s possible to implement action in the loop when my button is pressed
auto button = ui::Button::create(“enemy1.png”);
button->setTitleText(“Button Text”);
button->setPressedActionEnabled(true);
Size winSize = Director::sharedDirector()->getWinSize();
button->setPosition(ccp(winSize.width - (button->getContentSize().width / 2) - 10, button->getContentSize().height / 2 + 10));
button->addTouchEventListener([&](Ref* sender, ui::Widget::TouchEventType type){
switch (type)
{
case ui::Widget::TouchEventType::BEGAN:
herobody->SetLinearVelocity(b2Vec2(1.5, 0));
break;
case ui::Widget::TouchEventType::ENDED:
break;
default:
break;
}
});
this->addChild(button);
I think i can make boolen in (case ui::Widget::TouchEventType::BEGAN:) and add herobody->SetLinearVelocity(b2Vec2(1.5, 0)); in time loop but is there any simpliest way to do that ?