【问题标题】:Disable MenuItemLabel Zoom feature on touch in cocos2d-x在 cocos2d-x 中禁用 MenuItemLabel 缩放功能
【发布时间】:2015-03-18 06:39:11
【问题描述】:

我在 cocos2d-x 3.3 中工作,它类似于 v3.0 之后的任何版本。 我想创建一个标签,其中文本的数量可以变化,并且还希望在触摸时进行回调。 我通过以下方式创建了它:

    Label* questionLabel = Label::create("", "Dimbo Regular.ttf", 36);
    questionLabel->setColor(Color3B(190, 30, 45));
    questionLabel->setDimensions(900, 120);
    questionLabel->setHorizontalAlignment(TextHAlignment::LEFT);
    questionLabel->setVerticalAlignment(TextVAlignment::CENTER);
    questionLabel->setString(questionString);
    MenuItemLabel* questionMenuLabel=MenuItemLabel::create(questionLabel, CC_CALLBACK_1(PreAssessment::questionPressedCallback, this));
    questionMenuLabel->setPosition(520,516.5);
    auto menu=Menu::create(questionMenuLabel,NULL);
    menu->setPosition(Vec2::ZERO);
    addChild(menu,1);

标签被创建,它也在调用回调方法。 我面临的唯一问题是,每当我触摸标签时,它都会给我一个缩放/缩放效果,直到触摸没有结束。

我想禁用缩放/缩放效果。

【问题讨论】:

    标签: cocos2d-x cocos2d-x-3.0


    【解决方案1】:

    您需要继承 MenuItemLabel 类并覆盖 selected() 方法

    class NoZoomMenuItemLabel : public MenuItemLabel{
    public:
    
        static NoZoomMenuItemLabel *create(Node*label, const ccMenuCallback& callback);
        virtual void selected() override;
    
    };
    
    // .cpp
    NoZoomMenuItemLabel * NoZoomMenuItemLabel::create(Node*label, const ccMenuCallback& callback)
    {
        NoZoomMenuItemLabel *ret = new (std::nothrow) NoZoomMenuItemLabel();
        ret->initWithLabel(label, callback);
        ret->autorelease();
        return ret;
    }
    
    void NoZoomMenuItemLabel::selected()
    {
        // do nothing
    }
    

    用法:

    NoZoomMenuItemLabel *questionMenuLabel = NoZoomMenuItemLabel::create(questionLabel, [](Ref *pSender){
        log("Click !");
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-22
      • 2012-10-30
      • 1970-01-01
      • 1970-01-01
      • 2016-03-01
      • 2012-02-24
      相关资源
      最近更新 更多