cocos2dx lua和c 紋理平鋪

2021-08-11 08:48:44 字數 921 閱讀 8089

lua:

local bg = cc.sprite:create("test.png");

bg:gettexture():settexparameters(gl_linear, gl_linear, gl_repeat, gl_repeat);

bg:settexturerect(cc.rect(0, 0, 1136, 1024));

bg:setscaley(640/1024);

bg:setposition(cc.p(self._size.width/2, self._size.height/2));

self:addchild(bg);

c++:

texture2d* texture = director::getinstance()->gettexturecache()->addimage("test.png");

texture2d::texparams tp = ;

texture->settexparameters(tp);

auto bg = sprite::createwithtexture(texture, rect(0 , 0, 1136, 1024));

bg->setscaley(640/1024);

bg->setposition(vec2(1136/2, 1024/2));

this->addchild(bg, 0);

上面兩個例子中的setscaley是因為平鋪的size的寬和高只能2的n次方(n為任意整數,至於為什麼一定要是2的n次方,看c++源**)。所以如果你要的平鋪後的效果是1036*640,美術做出來的是16*640的,這個是不能用的,只能做乙個16*1024的,平鋪之後,再用setscaley縮放。

兩個基本的紋理過濾規則:

文章參考:

cocos2d x lua呼叫c 函式

test.h extern c int getstring lua state l test.cpp include test.h using namespace std int getstring lua state l 這時候就可以用取到的引數了,可以用作呼叫c 函式的引數 function 將...

Cocos2d x Lua基本操作

1.lua庫引用 目錄新增 lua lua luajit include lib新增 lua51.lib 2.開啟lua庫 示例 lua state pl lua open luaopen base pl luaopen math pl luaopen string pl 3.讀取lua值 示例 1...

cocos2dx lua優化總結

渲染效率 紋理格式 執行效率 記憶體 包大小 cpp view plain copy 安卓啟用4444紋理 iftargetplatform cc.platform os android then cc.texture2d setdefaultalphapixelformat cc.texture2...