cocos2dx js灰化高亮等等

2021-07-30 10:53:48 字數 3811 閱讀 8708

// 給節點設定自定義的shader

cc.node.prototype.setcustomshader = function (vsh, fsh, enable)

// 判斷是不是widget

if (this.getvirtualrenderer != null && this.getvirtualrenderer().getsprite != null) else if (this.getvirtualrenderer != null)

_nodesetcustomshader(node, vsh, fsh, enable);

children = this.getchildren();

for (i in children)

children[i].setcustomshader(vsh, fsh, enable);

}//控制項內部節點

if (this.getprotectedchildren != null)

}};

// 給動畫設定shaer, 動畫的置灰跟普通節點的置灰不太一樣,所以需要特殊設定

ccs.armature.prototype.setcustomshader = function (vsh, fsh, enable)

bones = this.getbonedic();

for (key in bones)

}};

// 乙個基礎函式,用於實現下面的setcustomshader功能

var _nodesetcustomshader = function (node, vsh, fsh, enable)

nodeprogram = node.getshaderprogram();

// 建立shader

if (enable === true)

program = cc.shadercache.getprogram(vsh + _fsh);

if (program == null)

} else else

}if (program != null/* && nodeprogram != null*/)

node.setshaderprogram(program);

};

// 效果指令碼

灰化:gray.fsh

#ifdef gl_es

precision mediump float;

#endif

varying vec4 v_fragmentcolor;

varying vec2 v_texcoord;

void main()

gray.vsh

attribute vec4 a_position;

attribute vec2 a_texcoord;

attribute vec4 a_color;

#ifdef gl_es

varying lowp vec4 v_fragmentcolor;

varying mediump vec2 v_texcoord;

#else

varying vec4 v_fragmentcolor;

varying vec2 v_texcoord;

#endif

void main()

// 將乙個節點高亮

highlight.fsh

#ifdef gl_es

precision mediump float;

#endif

varying vec4 v_fragmentcolor;

varying vec2 v_texcoord;

void main()

highlight.vsh

attribute vec4 a_position;

attribute vec2 a_texcoord;

attribute vec4 a_color;

#ifdef gl_es

varying lowp vec4 v_fragmentcolor;

varying mediump vec2 v_texcoord;

#else

varying vec4 v_fragmentcolor;

varying vec2 v_texcoord;

#endif

void main()

highlightetca.fsh

#ifdef gl_es

precision mediump float;

#endif

varying vec4 v_fragmentcolor;

varying vec2 v_texcoord;

void main()

// 將乙個節點高亮, 主要是針對iu條件

uihighlight.fsh

#ifdef gl_es

precision mediump float;

#endif

varying vec4 v_fragmentcolor;

varying vec2 v_texcoord;

void main()

uihighlight.vsh

attribute vec4 a_position;

attribute vec2 a_texcoord;

attribute vec4 a_color;

#ifdef gl_es

varying lowp vec4 v_fragmentcolor;

varying mediump vec2 v_texcoord;

#else

varying vec4 v_fragmentcolor;

varying vec2 v_texcoord;

#endif

void main()

// 將乙個節點按照sin曲線高亮

highlightsin.fsh

#ifdef gl_es

precision mediump float;

#endif

#define speed 15

#define scale 1.5

varying vec4 v_fragmentcolor;

varying vec2 v_texcoord;

void main()

highlightsin.vsh

attribute vec4 a_position;

attribute vec2 a_texcoord;

attribute vec4 a_color;

#ifdef gl_es

varying lowp vec4 v_fragmentcolor;

varying mediump vec2 v_texcoord;

#else

varying vec4 v_fragmentcolor;

varying vec2 v_texcoord;

#endif

void main()

cocos2dx js 多層級列表

先上圖 如上圖所示,多層級列表可以展開其子層級列表 cocos2dx中有乙個tableview,使用它製作列表是乙個比較好的選擇 一般使用tableview製作的都是一級列表,這裡利用tableview來製作乙個多層級列表 下面直接上 檔案commonlist.js 多級列表 預設只渲染一級列表項 ...

cocos2dx js更換遊戲引擎版本(mac)

專案建立之初使用cocos2dx js 3.16的版本,但專案使用android studio 打包出來的apk包在部分機型上安裝不了,但公司其他專案使用cocos2dx js 3.15版本是沒問題的,於是將就需要首先切換電腦遊戲引擎版本。1 開啟終端,cd 到cocos2dx js 1.15引擎包...

cocos2dx js 實現自定義富文字

在做遊戲的時候,有乙個特殊的需求引擎沒有直接提供。一段label有一部分是其他顏色,例如 乙隻 優雅 的 攻城獅 上面這個label,一般想到的常規方式是 用四個label拼接,放到不同的位置。其實richtext是提供了這種功能的,用設定好的四個richelementtext就能實現。但是相對來說...