@564276732 写道:
测试场景
Scene *scene = Scene::create();
Director::getInstance()->runWithScene(scene);
Button* btn = Button::create("res/Image/Common/Frame23.png");
btn->addTouchEventListener([=](Ref* sender, Widget::TouchEventType type){
if (type == Widget::TouchEventType::ENDED){
CCLOG("22222");
}
});
btn->setPosition(Vec2(320,800));
scene->addChild(btn);Layer* l = Layer::create(); Director::getInstance()->setNotificationNode(l); Widget* widget= (Widget*)CSLoader::createNode("res/Image/Dialog/NetConfirmDialog.csb"); widget->setContentSize(Director::getInstance()->getWinSize()); Helper::doLayout(widget); l->addChild(widget); Button* btn2 = (Button*)Helper::seekWidgetByName(widget,"confirmBtn"); btn2->addTouchEventListener([=](Ref* sender, Widget::TouchEventType type){ if (type == Widget::TouchEventType::ENDED){ CCLOG("1111111"); } }); btn2->setTouchPriority(-2); Helper::seekWidgetByName(widget,"bgPanel")->setTouchPriority(-1); Helper::seekWidgetByName(widget,"bgPanel")->addTouchEventListener([=](Ref* sender, Widget::TouchEventType type){ if (type == Widget::TouchEventType::ENDED){ CCLOG("33333"); } });
修改Widget:
void Widget::setTouchPriority(int priority)
{
if(_touchListener){
eventDispatcher->removeEventListener(touchListener);
eventDispatcher->addEventListenerWithFixedPriority(touchListener, priority);}
}
bool Widget::onTouchBegan(Touch *touch, Event *unusedEvent)
{
_hitted = false;
if (isVisible() && isEnabled() && isAncestorsEnabled() && isAncestorsVisible(this) )
{
_touchBeganPosition = touch->getLocation();
auto camera = Camera::getVisitingCamera();
if(camera == nullptr){
camera = Director::getInstance()->getRunningScene()->getDefaultCamera();
}
if(hitTest(_touchBeganPosition, camera, nullptr))
{
if (isClippingParentContainsPoint(_touchBeganPosition)) {
_hittedByCamera = camera;
_hitted = true;
}
}
}
if (!_hitted)
{
return false;
}
setHighlighted(true);/* * Propagate touch events to its parents */ if (_propagateTouchEvents) { this->propagateTouchEvent(TouchEventType::BEGAN, this, touch); } pushDownEvent(); return true;
}
这样做虽然是可以让NotificationNode上的按钮触发点击,但是能不能提供一个更方便的NotificationNode 让人使用
帖子: 1
参与者: 1