有人说我是策划转行的程序,让我想了好久!

星际巡航-如何不再迷失自我

有人说我是策划转行的程序,我说是程序转学策划,你们看了就相信了!

onLoad() {
let array = [‘1’,‘2’,‘3’,‘4’,‘5’];
//过虑出数组中的奇数元素
this._num = 2;
array = array.map(function(i) {
return parseInt(i);
}.filter(function(i) {
return i % this._num;
}, this); //注意这里的this参数

} 这里面的filter函数应该用在)外面吧

感谢你的指正,确实在这里有个语法错误,是map函数少了后面封闭的圆括号

onLoad() {
    let array = ['1','2','3','4','5'];
    this._num = 2;
    array = array.map(function(i) {
        return parseInt(i);
    }).filter(function(i) {
        return i % this._num;
    }, this); //注意这里的this参数
    cc.log(array);
}

文章中还有一个地方,非常惭愧,将Button子节点变灰的实现上,只能用于Web上,在原生上会有错误。我试了一些其它方法,设置label的ShaderProgram或GLProgramState,在原生上Label总是无效,这里向大家请教了。

//先保存button状态切换函数
let updateState = cc.Button.prototype._updateState;
//自己写个函数来将他覆盖了
cc.Button.prototype._updateState = function () {
    //执行时的第一句,执行原来保存的_updateState,相当于执行基类函数
    //这里不能直接调用updateState,需要用call将内部this修正为当前button
    updateState.call(this); 
    if (this.node.interactable === this.interactable) {
        return;
    }
    //下面是根据是否禁用,设置button节点下的子节点变灰
    //做了条件判断只在不设置disabledSprite时生效
    this.node.interactable = this.interactable;
    if (this.enableAutoGrayEffect && this.transition !== cc.Button.Transition.COLOR) {
        if (!(this.transition === cc.Button.Transition.SPRITE && this.disabledSprite)) {
            this.node.children.forEach((node) => {
                let sprite = node.getComponent(cc.Sprite);
                if (sprite && sprite._sgNode) {
                    sprite._sgNode.setState(this.interactable ? 0 : 1);
                }
                /*
                let label = node.getComponent(cc.Label);
                if (label && label._sgNode) {
                    //在原生上没有这些属性方法,只能用于浏览器上
                    //cc.shaderCache.programForKey / cc.Scale9Sprite.WebGLRenderCmd
                    let shaderProgram = this.interactable ?
                        cc.shaderCache.programForKey(cc.macro.SHADER_SPRITE_POSITION_TEXTURECOLOR) :     
                        cc.Scale9Sprite.WebGLRenderCmd._getGrayShaderProgram();
                    
                    label._sgNode._renderCmd.setShaderProgram(shaderProgram);
                }
              */
            });
        }
    }
};

1赞

你好牛,jsb上label你是怎么做的,我试了好几种方法没成功。,剩下的方法就是动c++了。