求大神指导啊:没有与这些操作数匹配的“==”运算符!!!

#include “beijing1.h”
#include “SimpleAudioEngine.h”
#include “ui/CocosGUI.h”
#include <HelloWorldScene.h>
#include
USING_NS_CC;
using namespace cocos2d::ui;
Scene* beijing1::createScene()
{
return beijing1::create();
}
bool beijing1::init()
{
if (!Scene::init())
{
return false;
}
auto text = Text::create();
text->setTag(1);
text->setText(“0 %”)
//省略部分
this->addChild(text, 2);

auto slider = Slider::create();
 //省略部分
slider->setTag(2);
slider->addTouchEventListener([&](Ref* sender, Widget::TouchEventType type) {
    switch (type)
    {
        if(type == Slider::EventType::ON_PERCENTAGE_CHANGED) //###问题在这里的==上###
        {
        auto slider = dynamic_cast<Slider*>(sender);    
        int percent = slider->getPercent();
        Text* text = NULL;
        if (slider->getTag() == 2)
            text = dynamic_cast<Text*>(getChildByTag(1));
        text->setString(String::createWithFormat("% % %d", percent)->getCString());
        }
    }
    });
this->addChild(slider,2);
return true;

}

//问题:没有与这些操作数匹配的“==”运算符

这时什么神仙写法。。。。
不是应该:
switch (type) {
case Slider::EventType::ON_PERCENTAGE_CHANGED:
…to do;
break;
}
或者:
if (type == Slider::EventType::ON_PERCENTAGE_CHANGED) {
… to do;
}
两个这么糅合是啥意思

我删了switch(type){}这些还是不行啊,哭,,,还是说没有==

不对,你这里事件监听错了,不是监听touch事件,应该是监听你slider自己的事件。你查下有没有slider->addEventListener的方法,这种回调应该是Slider::EventType的,touch事件一般就是按下、移动、弹起、取消,没有百分比改变这种东西

2赞

语法、、、、、、 :face_with_thermometer:

谢谢大神!我结合你说的,加上看官方demo,还有查阅资料,总算搞定了这点东西。
现在在上大学,自学之路艰辛啊,现在把比较简单的精灵、场景、动作、UI这些粗浅地学了个大概,就是不知道要学到什么程度才有人要。 :joy:·········································································································································

可以考虑设计个自己的demo,应届生项目经验还是很加分的

大佬,又又出问题了 :sob:,导出安卓apk文件失败,下面是命令窗口显的,看不懂啊 :sob: :sob: :sob:

编译模式:debug
使用 Android Studio 工程:D:\360Downloads\Mygame\UI\proj.android
正在生成 apk 文件…
正在执行:’“D:\360Downloads\Mygame\UI\proj.android\gradlew.bat” --parallel --info assembleDebug -PPROP_BUILD_TYPE=cmake’

Unzipping C:\Users\Administrator.gradle\wrapper\dists\gradle-4.6-all\5vpsfhg9sgbuqofrbh1l21ueq4\gradle-4.6-all.zip to C:\Users\Administrator.gradle\wrapper\dists\gradle-4.6-all\5vpsfhg9sgbuqofrbh1l21ueq4
Exception in thread “main” java.lang.RuntimeException: java.util.zip.ZipException: zip END header not found
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:78)
at org.gradle.wrapper.Install.createDist(Install.java:47)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: java.util.zip.ZipException: zip END header not found
at java.base/java.util.zip.ZipFile$Source.zerror(ZipFile.java:1587)
at java.base/java.util.zip.ZipFile$Source.findEND(ZipFile.java:1441)
at java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1450)
at java.base/java.util.zip.ZipFile$Source.(ZipFile.java:1263)
at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1225)
at java.base/java.util.zip.ZipFile$CleanableResource.(ZipFile.java:706)
at java.base/java.util.zip.ZipFile.(ZipFile.java:240)
at java.base/java.util.zip.ZipFile.(ZipFile.java:171)
at java.base/java.util.zip.ZipFile.(ZipFile.java:185)
at org.gradle.wrapper.Install.unzip(Install.java:160)
at org.gradle.wrapper.Install.access$400(Install.java:29)
at org.gradle.wrapper.Install$1.call(Install.java:70)
at org.gradle.wrapper.Install$1.call(Install.java:47)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
… 3 more
执行命令出错,返回值:1。

打包的命令是:PS D:\360Downloads\Mygame\UI> cocos compile -p android
问题可能是Java的jdk没找对位置,但是已经试了很多路径了

我是非相关专业做demo也可以么,原本就是打算把整体学个大概,再自己设计一个demo,虽然做的时候肯定会出各种各样的问题,但也算是实践中学习了。 :joy:

这个只有你自己去搜搜关键字然后尝试着改了,这块如果不是恰好遇到过和你相同操作的人一般很难给出有建设性的意见

该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。