Cocos Coretor Js 精靈節點置灰

2021-08-29 10:16:52 字數 2460 閱讀 7378

首先先吐個槽,cocos的資料實在是太少了,遇到點問題,找半天,都沒有乙個清晰的答案,網上大部分的資料都是c++和lua的**,對於我這只會懂點皮毛的js玩家來說,上手實在是坑,難得找到一點能看得懂得**。不容易....

廢話不多說,進入正題,cocos精靈節點灰化的實現,主要還是使用內建 shader ,通過修改 glprogram 中屬性,來重新渲染精靈sprite  ,這是我參考這位大嬸封裝得一點**

//灰化

togray: function (node) ",

fshader: "varying vec4 v_fragmentcolor; \nvarying vec2 v_texcoord; \n//uniform sampler2d cc_texture0; \nvoid main() \n"

var program = new cc.glprogram();

program.initwithvertexshaderbytearray(grayshader.vshader, grayshader.fshader);

program.addattribute(cc.macro.attribute_name_position, cc.macro.vertex_attrib_position);

program.addattribute(cc.macro.attribute_name_color, cc.macro.vertex_attrib_color);

program.addattribute(cc.macro.attribute_name_tex_coord, cc.macro.vertex_attrib_tex_coords);

program.link();

program.updateuniforms();

sprite._sgnode.shaderprogram = program;

//正常

tonoramal: function (node) ",

fshader: "varying vec4 v_fragmentcolor; \nvarying vec2 v_texcoord; \n//uniform sampler2d cc_texture0; \nvoid main() \n"

var program = new cc.glprogram();

program.initwithvertexshaderbytearray(normalshader.vshader, normalshader.fshader);

program.addattribute(cc.macro.attribute_name_position, cc.macro.vertex_attrib_position);

program.addattribute(cc.macro.attribute_name_color, cc.macro.vertex_attrib_color);

program.addattribute(cc.macro.attribute_name_tex_coord, cc.macro.vertex_attrib_tex_coords);

program.link();

program.updateuniforms();

sprite._sgnode.shaderprogram = program;

//高亮

tolight: function (node) ",

fshader: "varying vec4 v_fragmentcolor; \nvarying vec2 v_texcoord; \n//uniform sampler2d cc_texture0; \nvoid main() \n"

var program = new cc.glprogram();

program.initwithvertexshaderbytearray(highlightshader.vshader, highlightshader.fshader);

program.addattribute(cc.macro.attribute_name_position, cc.macro.vertex_attrib_position);

program.addattribute(cc.macro.attribute_name_color, cc.macro.vertex_attrib_color);

program.addattribute(cc.macro.attribute_name_tex_coord, cc.macro.vertex_attrib_tex_coords);

program.link();

program.updateuniforms();

sprite._sgnode.shaderprogram = program;

呼叫方法   

灰化: this.togray(this.loginbtn); //loginbtn是我得登入按鈕,是乙個精靈節點

正常: this.tonoramal(this.loginbtn); //loginbtn是我得登入按鈕,是乙個精靈節點

噢啦!

高精加 高精乘

高精度演算法是每個初學者的入門必備,在我們做題目的時候,總會遇到一下精度太高的問題,即使用了long long也遠遠不夠。所以學習高精度也是很有必要的。本篇文章就以下面這道題為例子,簡單介紹一下高精加和高精乘。洛谷原題 洛谷部落格題解 本蒟的思路就是高精乘 高精加,就是把高精乘的模板套上去接著套高精...

c 高精除以高精

include using namespace std int a 1000 b 1000 int len1,len2,len int index int re 1000 p 0 記錄結果 intjudge return0 int main for i 0 isize i len1 n.size l...

樹屋階梯(卡特蘭數 高精除低精 高精乘低精)

安徽省選 2012 題目描述 暑假期間,小龍報名了乙個模擬野外生存作戰訓練班來鍛鍊體魄,訓練的第乙個晚上,教官就給他們出了個難題。由於地上露營濕氣重,必須選擇在高處的樹屋露營。小龍分配的樹屋建立在一顆高度為 n 1 尺 n 為正整數 的大樹上,正當他發愁怎麼爬上去的時候,發現旁邊堆滿了一些空心四方鋼...