creator 踩坑收集

cc.Class({
extends: cc.Component,
properties: {
result_tip_success : ‘Congratulations! This time the score is’,
result_tip_err : ‘Continue to cheer! This time the score is’,
},
my function(){
var last_sorce= this.node.getChildByName(‘fenshuValue’).getComponent(cc.Label).string;
var last_result_tip = this.result_menu.getChildByName(‘tip’).getComponent(cc.Label).string;

        if(last_sorce >=150){
          this.result_menu.getChildByName('tip').getComponent(cc.Label).string = this.result_tip_success;
               cc.log(">>>>>>");

             }else{ // 小于150
              this.result_menu.getChildByName('tip').getComponent(cc.Label).string = this.result_tip_err;
            //     let last_result_tip = 'Continue to cheer! This time the score is';
                cc.log("<<<<<<<");

             }

},
如题,1.为啥在creator-js脚本里 last_sorce 字符串不需要转换成int类型就可以直接进行>=150判断?
类比“200”>=150这样可以进行???

2.为啥 var last_result_tip = this.result_menu.getChildByName(‘tip’).getComponent(cc.Label).string;
后 last_result_tip = this.result_tip_err;
却不显示,没效果??
直接用
this.result_menu.getChildByName(‘tip’).getComponent(cc.Label).string = this.result_tip_err;
就有效果了
难道js 的类型赋值时,不能用var 或者 let 声明变量类型后,取变量类型再赋值不能???
只能直接取值后赋值?? this.result_menu.getChildByName(‘tip’).getComponent(cc.Label).string = this.result_tip_err;

1赞

先补一下 JS 的基础吧

“200”>=150 JS 这样是比值不管类型, === 三个等号比类型

var last_result_tip = this.result_menu.getChildByName(‘tip’).getComponent(cc.Label).string;

这个 .string 里面是 JS 属性的特性实现了 getter 和 setter ,里面的 get set 函数来赋值更新等操作,补一下 JS 基础吧

last_result_tip = this.result_tip_err; 当然就没有效果了

这完全是语法基础问题,和 creator 哪有关系呀

虽然我也很想吐槽 creator 各种问题····

哈哈哈哈哈哈

谢谢指教[quote=“lizhenda, post:2, topic:82175, full:true”]
先补一下 JS 的基础吧

“200”>=150 JS 这样是比值不管类型, === 三个等号比类型

var last_result_tip = this.result_menu.getChildByName(‘tip’).getComponent(cc.Label).string;

这个 .string 里面是 JS 属性的特性实现了 getter 和 setter ,里面的 get set 函数来赋值更新等操作,补一下 JS 基础吧

last_result_tip = this.result_tip_err; 当然就没有效果了
[/quote]

嗯嗯额

预制定节点加载网络图片,将图片变灰,为什么没有生效?

你可以在图片上层添加一个maskLayer,
遮罩一下
类似这样:
this.maskLayer.active = true;
this.maskLayer.opacity = 1;
this.maskLayer.color = cc.Color.BLACK;
this.maskLayer.runAction(
cc.sequence( // 顺序执行动作,创建的动作将按顺序依次运行。
cc.fadeIn(0.2), // 渐显效果
cc.callFunc(() => { // 执行回调函数
// 重新加载场景
cc.director.loadScene(‘bird_game’);
}, this)
)
)
仅供参考。