Merge pull request #11630 from samuele3hu/v3.6_test1

Add Lua-bindings for SpritePolygon and related test case
This commit is contained in:
minggo 2015-04-28 20:13:52 +08:00
commit 48729b653f
8 changed files with 918 additions and 6 deletions

View File

@ -2097,6 +2097,194 @@ bool luaval_to_texparams(lua_State* L,int lo,cocos2d::Texture2D::TexParams* outV
return ok;
}
bool luaval_to_tex2f(lua_State* L, int lo, cocos2d::Tex2F* outValue, const char* funcName)
{
if (nullptr == L || nullptr == outValue)
return false;
bool ok = true;
tolua_Error tolua_err;
if (!tolua_istable(L, lo, 0, &tolua_err) )
{
#if COCOS2D_DEBUG >=1
luaval_to_native_err(L,"#ferror:",&tolua_err,funcName);
#endif
ok = false;
}
if (ok)
{
lua_pushstring(L, "u");
lua_gettable(L, lo);
outValue->u = lua_isnil(L, -1) ? 0 : lua_tonumber(L, -1);
lua_pop(L, 1);
lua_pushstring(L, "v");
lua_gettable(L, lo);
outValue->v = lua_isnil(L, -1) ? 0 : lua_tonumber(L, -1);
lua_pop(L, 1);
}
return ok;
}
bool luaval_to_v3f_c4b_t2f(lua_State* L,int lo,cocos2d::V3F_C4B_T2F * outValue, const char* funcName)
{
if (nullptr == L || nullptr == outValue)
return false;
bool ok = true;
tolua_Error tolua_err;
if (!tolua_istable(L, lo, 0, &tolua_err) )
{
#if COCOS2D_DEBUG >=1
luaval_to_native_err(L,"#ferror:",&tolua_err,funcName);
#endif
ok = false;
}
if (ok)
{
lua_pushstring(L, "vertices");
lua_gettable(L, lo);
if (!tolua_istable(L,lua_gettop(L), 0, &tolua_err))
{
lua_pop(L, 1);
return false;
}
ok &= luaval_to_vec3(L, lua_gettop(L), &outValue->vertices);
if (!ok)
{
lua_pop(L, 1);
return false;
}
lua_pop(L, 1);
lua_pushstring(L, "colors");
lua_gettable(L, lo);
if (!tolua_istable(L, lua_gettop(L), 0, &tolua_err))
{
lua_pop(L, 1);
return false;
}
ok &= luaval_to_color4b(L, lua_gettop(L), &outValue->colors);
if (!ok)
{
lua_pop(L, 1);
return false;
}
lua_pop(L, 1);
lua_pushstring(L, "texCoords");
lua_gettable(L, lo);
if (!tolua_istable(L, lua_gettop(L), 0, &tolua_err))
{
lua_pop(L, 1);
return false;
}
ok &= luaval_to_tex2f(L, lua_gettop(L), &outValue->texCoords);
if (!ok)
{
lua_pop(L, 1);
return false;
}
lua_pop(L, 1);
}
return ok;
}
bool luaval_to_std_vector_vec2(lua_State* L, int lo, std::vector<cocos2d::Vec2>* ret, const char* funcName)
{
if (nullptr == L || nullptr == ret || lua_gettop(L) < lo)
return false;
tolua_Error tolua_err;
bool ok = true;
if (!tolua_istable(L, lo, 0, &tolua_err))
{
#if COCOS2D_DEBUG >=1
luaval_to_native_err(L,"#ferror:",&tolua_err,funcName);
#endif
ok = false;
}
if (ok)
{
size_t len = lua_objlen(L, lo);
cocos2d::Vec2 value;
for (size_t i = 0; i < len; i++)
{
lua_pushnumber(L, i + 1);
lua_gettable(L,lo);
if (lua_istable(L, lua_gettop(L)))
{
ok &= luaval_to_vec2(L, lua_gettop(L), &value);
if (ok)
{
ret->push_back(value);
}
}
else
{
CCASSERT(false, "vec2 type is needed");
}
lua_pop(L, 1);
}
}
return ok;
}
bool luaval_to_std_vector_v3f_c4b_t2f(lua_State* L, int lo, std::vector<cocos2d::V3F_C4B_T2F>* ret, const char* funcName)
{
if (nullptr == L || nullptr == ret || lua_gettop(L) < lo)
return false;
tolua_Error tolua_err;
bool ok = true;
if (!tolua_istable(L, lo, 0, &tolua_err))
{
#if COCOS2D_DEBUG >=1
luaval_to_native_err(L,"#ferror:",&tolua_err,funcName);
#endif
ok = false;
}
if (ok)
{
size_t len = lua_objlen(L, lo);
cocos2d::V3F_C4B_T2F value;
for (size_t i = 0; i < len; i++)
{
lua_pushnumber(L, i + 1);
lua_gettable(L,lo);
if (lua_istable(L, lua_gettop(L)))
{
ok &= luaval_to_v3f_c4b_t2f(L, lua_gettop(L), &value);
if (ok)
{
ret->push_back(value);
}
}
else
{
CCASSERT(false, "V3F_C4B_T2F type is needed");
}
lua_pop(L, 1);
}
}
return ok;
}
void vec2_array_to_luaval(lua_State* L,const cocos2d::Vec2* points, int count)
{
if (NULL == L)

View File

@ -771,6 +771,53 @@ extern bool luaval_to_quaternion(lua_State* L,int lo,cocos2d::Quaternion* outVal
*/
extern bool luaval_to_texparams(lua_State* L,int lo,cocos2d::Texture2D::TexParams* outValue, const char* funcName = "");
/**
* Get a cocos2d::V3F_C4B_T2F object value from the given accpetable index of stack.
* If the value at the given accpetable index of stack is a table it returns true, otherwise returns false.
* If the table has the `vertices`, `colors`, and `texCoords` keys and the corresponding values are not nil, this function would assign the values to the corresponding members of outValue.
* @param L the current lua_State.
* @param lo the given accpetable index of stack.
* @param outValue the pointer to a cocos2d::V3F_C4B_T2F object which stores the values from the Lua table.
* @param funcName the name of calling function, it is used for error output in the debug model.
* @return true if the value at the given accpetable index of stack is a table, otherwise return false.
*/
extern bool luaval_to_v3f_c4b_t2f(lua_State* L,int lo,cocos2d::V3F_C4B_T2F* outValue, const char* funcName = "");
/**
* Get a cocos2d::Tex2F object value from the given accpetable index of stack.
* If the value at the given accpetable index of stack is a table it returns true, otherwise returns false.
* If the table has the `u`, and `v` keys and the corresponding values are not nil, this function would assign the values to the corresponding members of outValue.Otherwise, the value of members of outValue would be 0.
* @param L the current lua_State.
* @param lo the given accpetable index of stack.
* @param outValue the pointer to a cocos2d::Tex2F object which stores the values from the Lua table.
* @param funcName the name of calling function, it is used for error output in the debug model.
* @return true if the value at the given accpetable index of stack is a table, otherwise return false.
*/
extern bool luaval_to_tex2f(lua_State* L, int lo, cocos2d::Tex2F* outValue, const char* funcName = "");
/**
* Get a pointer points to a std::vector<cocos2d::V3F_C4B_T2F> from a Lua array table in the stack.
*
* @param L the current lua_State.
* @param lo the given accpetable index of stack.
* @param ret a pointer points to a std::vector<cocos2d::V3F_C4B_T2F>.
* @param funcName the name of calling function, it is used for error output in the debug model.
* @return Return true if the value at the given accpetable index of stack is a table, otherwise return false.
*/
extern bool luaval_to_std_vector_v3f_c4b_t2f(lua_State* L, int lo, std::vector<cocos2d::V3F_C4B_T2F>* ret, const char* funcName = "");
/**
* Get a pointer points to a std::vector<cocos2d::Vec2> from a Lua array table in the stack.
*
* @param L the current lua_State.
* @param lo the given accpetable index of stack.
* @param ret a pointer points to a std::vector<cocos2d::Vec2>.
* @param funcName the name of calling function, it is used for error output in the debug model.
* @return Return true if the value at the given accpetable index of stack is a table, otherwise return false.
*/
extern bool luaval_to_std_vector_vec2(lua_State* L, int lo, std::vector<cocos2d::Vec2>* ret, const char* funcName = "");
/**@}**/
// from native

View File

@ -3,6 +3,7 @@
#include "LuaBasicConversions.h"
#include "CCLuaValue.h"
#include "CCLuaEngine.h"
#include "2d/SpritePolygon.h"
static int lua_cocos2dx_experimental_TMXLayer_getTileGIDAt(lua_State* tolua_S)
{
@ -80,12 +81,237 @@ static void extendExperimentalTMXLayer(lua_State* tolua_S)
lua_pop(tolua_S, 1);
}
bool isVectorV3FC4BT2F(lua_State* tolua_S, int lo)
{
if (!lua_istable(tolua_S, lo))
return false;
lua_pushnumber(tolua_S, 1);
lua_gettable(tolua_S,lo);
if (!lua_istable(tolua_S, -1))
return false;
lua_pushstring(tolua_S, "vertices");
lua_gettable(tolua_S, -2);
if (lua_isnil(tolua_S, -1))
return false;
lua_pop(tolua_S, 1);
lua_pushstring(tolua_S, "colors");
lua_gettable(tolua_S, -2);
if (lua_isnil(tolua_S, -1))
return false;
lua_pop(tolua_S, 1);
lua_pushstring(tolua_S, "texCoords");
lua_gettable(tolua_S, -2);
if (lua_isnil(tolua_S, -1))
return false;
lua_pop(tolua_S, 1);
return true;
}
int lua_cocos2dx_experimental_SpritePolygon_create(lua_State* tolua_S)
{
int argc = 0;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertable(tolua_S,1,"ccexp.SpritePolygon",0,&tolua_err)) goto tolua_lerror;
#endif
argc = lua_gettop(tolua_S)-1;
do
{
if (argc == 3)
{
std::string arg0;
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.SpritePolygon:create");
if (!ok) { break; }
std::vector<cocos2d::Vec2> arg1;
if (isVectorV3FC4BT2F(tolua_S, 3))
break;
ok &= luaval_to_std_vector_vec2(tolua_S, 3, &arg1);
if (!ok) { break; }
std::vector<unsigned short> arg2;
ok &= luaval_to_std_vector_ushort(tolua_S, 4, &arg2, "ccexp.SpritePolygon:create");
if (!ok) { break; }
cocos2d::experimental::SpritePolygon* ret = cocos2d::experimental::SpritePolygon::create(arg0, arg1, arg2);
object_to_luaval<cocos2d::experimental::SpritePolygon>(tolua_S, "ccexp.SpritePolygon",(cocos2d::experimental::SpritePolygon*)ret);
return 1;
}
} while (0);
ok = true;
do
{
if (argc == 4)
{
std::string arg0;
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.SpritePolygon:create");
if (!ok) { break; }
std::vector<cocos2d::Vec2> arg1;
ok &= luaval_to_std_vector_vec2(tolua_S, 3, &arg1);
if (!ok) { break; }
std::vector<unsigned short> arg2;
ok &= luaval_to_std_vector_ushort(tolua_S, 4, &arg2, "ccexp.SpritePolygon:create");
if (!ok) { break; }
cocos2d::Rect arg3;
ok &= luaval_to_rect(tolua_S, 5, &arg3, "ccexp.SpritePolygon:create");
if (!ok) { break; }
cocos2d::experimental::SpritePolygon* ret = cocos2d::experimental::SpritePolygon::create(arg0, arg1, arg2, arg3);
object_to_luaval<cocos2d::experimental::SpritePolygon>(tolua_S, "ccexp.SpritePolygon",(cocos2d::experimental::SpritePolygon*)ret);
return 1;
}
} while (0);
ok = true;
do
{
if (argc == 3)
{
std::string arg0;
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.SpritePolygon:create");
if (!ok) { break; }
std::vector<cocos2d::V3F_C4B_T2F> arg1;
if (!isVectorV3FC4BT2F(tolua_S, 3))
break;
ok &= luaval_to_std_vector_v3f_c4b_t2f(tolua_S, 3, &arg1);
if (!ok) { break; }
std::vector<unsigned short> arg2;
ok &= luaval_to_std_vector_ushort(tolua_S, 4, &arg2, "ccexp.SpritePolygon:create");
if (!ok) { break; }
cocos2d::experimental::SpritePolygon* ret = cocos2d::experimental::SpritePolygon::create(arg0, arg1, arg2);
object_to_luaval<cocos2d::experimental::SpritePolygon>(tolua_S, "ccexp.SpritePolygon",(cocos2d::experimental::SpritePolygon*)ret);
return 1;
}
} while (0);
ok = true;
do
{
if (argc == 2)
{
std::string arg0;
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.SpritePolygon:create");
if (!ok) { break; }
std::vector<cocos2d::Vec2> arg1;
ok &= luaval_to_std_vector_vec2(tolua_S, 3, &arg1);
if (!ok) { break; }
cocos2d::experimental::SpritePolygon* ret = cocos2d::experimental::SpritePolygon::create(arg0, arg1);
object_to_luaval<cocos2d::experimental::SpritePolygon>(tolua_S, "ccexp.SpritePolygon",(cocos2d::experimental::SpritePolygon*)ret);
return 1;
}
} while (0);
ok = true;
do
{
if (argc == 3)
{
std::string arg0;
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.SpritePolygon:create");
if (!ok) { break; }
std::vector<cocos2d::Vec2> arg1;
if (isVectorV3FC4BT2F(tolua_S, 3))
break;
ok &= luaval_to_std_vector_vec2(tolua_S, 3, &arg1);
if (!ok) { break; }
cocos2d::Rect arg2;
ok &= luaval_to_rect(tolua_S, 4, &arg2, "ccexp.SpritePolygon:create");
if (!ok) { break; }
cocos2d::experimental::SpritePolygon* ret = cocos2d::experimental::SpritePolygon::create(arg0, arg1, arg2);
object_to_luaval<cocos2d::experimental::SpritePolygon>(tolua_S, "ccexp.SpritePolygon",(cocos2d::experimental::SpritePolygon*)ret);
return 1;
}
} while (0);
ok = true;
do
{
if (argc == 1)
{
std::string arg0;
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.SpritePolygon:create");
if (!ok) { break; }
cocos2d::experimental::SpritePolygon* ret = cocos2d::experimental::SpritePolygon::create(arg0);
object_to_luaval<cocos2d::experimental::SpritePolygon>(tolua_S, "ccexp.SpritePolygon",(cocos2d::experimental::SpritePolygon*)ret);
return 1;
}
} while (0);
ok = true;
do
{
if (argc == 2)
{
std::string arg0;
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.SpritePolygon:create");
if (!ok) { break; }
cocos2d::Rect arg1;
ok &= luaval_to_rect(tolua_S, 3, &arg1, "ccexp.SpritePolygon:create");
if (!ok) { break; }
cocos2d::experimental::SpritePolygon* ret = cocos2d::experimental::SpritePolygon::create(arg0, arg1);
object_to_luaval<cocos2d::experimental::SpritePolygon>(tolua_S, "ccexp.SpritePolygon",(cocos2d::experimental::SpritePolygon*)ret);
return 1;
}
} while (0);
ok = true;
do
{
if (argc == 3)
{
std::string arg0;
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.SpritePolygon:create");
if (!ok) { break; }
cocos2d::Rect arg1;
ok &= luaval_to_rect(tolua_S, 3, &arg1, "ccexp.SpritePolygon:create");
if (!ok) { break; }
double arg2;
ok &= luaval_to_number(tolua_S, 4,&arg2, "ccexp.SpritePolygon:create");
if (!ok) { break; }
cocos2d::experimental::SpritePolygon* ret = cocos2d::experimental::SpritePolygon::create(arg0, arg1, arg2);
object_to_luaval<cocos2d::experimental::SpritePolygon>(tolua_S, "ccexp.SpritePolygon",(cocos2d::experimental::SpritePolygon*)ret);
return 1;
}
} while (0);
ok = true;
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d", "ccexp.SpritePolygon:create",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_SpritePolygon_create'.",&tolua_err);
#endif
return 0;
}
static void extendExperimentalSpritePolygon(lua_State* tolua_S)
{
lua_pushstring(tolua_S, "ccexp.SpritePolygon");
lua_rawget(tolua_S, LUA_REGISTRYINDEX);
if (lua_istable(tolua_S,-1))
{
tolua_function(tolua_S, "create", lua_cocos2dx_experimental_SpritePolygon_create);
}
lua_pop(tolua_S, 1);
}
int register_all_cocos2dx_experimental_manual(lua_State* L)
{
if (nullptr == L)
return 0;
extendExperimentalTMXLayer(L);
extendExperimentalSpritePolygon(L);
return 0;
}

View File

@ -3355,6 +3355,46 @@ int tolua_cocos2dx_DrawNode_drawPoints(lua_State* tolua_S)
return 0;
}
}
else if (argc == 4)
{
unsigned int size;
luaval_to_uint32(tolua_S, 3, &size, "cc.DrawNode:drawPoints");
if ( size > 0 )
{
cocos2d::Vec2* points = new cocos2d::Vec2[size];
if (nullptr == points)
return 0;
for (int i = 0; i < size; i++)
{
lua_pushnumber(tolua_S,i + 1);
lua_gettable(tolua_S,2);
if (!tolua_istable(tolua_S,-1, 0, &tolua_err))
{
CC_SAFE_DELETE_ARRAY(points);
#if COCOS2D_DEBUG >= 1
goto tolua_lerror;
#endif
}
if(!luaval_to_vec2(tolua_S, lua_gettop(tolua_S), &points[i], "cc.DrawNode:drawPoints"))
{
lua_pop(tolua_S, 1);
CC_SAFE_DELETE_ARRAY(points);
return 0;
}
lua_pop(tolua_S, 1);
}
float pointSize = (float)tolua_tonumber(tolua_S, 4, 0);
cocos2d::Color4F color;
ok &=luaval_to_color4f(tolua_S, 5, &color, "cc.DrawNode:drawPoints");
if(!ok)
return 0;
self->drawPoints(points, size, pointSize, color);
return 0;
}
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.DrawNode:drawPoints",argc, 3);
return 0;

View File

@ -0,0 +1,407 @@
local imageFileName = "Images/grossini.png"
local function initDefaultSprite(filename, spp, layer)
layer:addChild(spp)
local s = cc.Director:getInstance():getWinSize()
local offset = cc.p(0.15 * s.width, 0)
spp:setPosition(s.width/2 + 0.15 * s.width, s.height/2)
local sp = cc.Sprite:create(imageFileName)
layer:addChild(sp)
sp:setPosition(s.width/2 - 0.15 * s.width, s.height/2)
local debugForNormalSprite = cc.DrawNode:create()
sp:addChild(debugForNormalSprite)
local touchListener = cc.EventListenerTouchOneByOne:create()
touchListener:registerScriptHandler(function (touch, event)
spp:showDebug(true)
debugForNormalSprite:setVisible(true)
return true
end,cc.Handler.EVENT_TOUCH_BEGAN)
touchListener:registerScriptHandler(function (touch, event)
local pos = touch:getDelta()
local newScale = cc.clampf(spp:getScale()+pos.x*0.01, 0.1, 2)
spp:setScale(newScale)
sp:setScale(newScale)
end,cc.Handler.EVENT_TOUCH_MOVED)
touchListener:registerScriptHandler(function (touch, event)
spp:showDebug(false)
debugForNormalSprite:setVisible(false)
end,cc.Handler.EVENT_TOUCH_ENDED)
local eventDispatcher = layer:getEventDispatcher()
eventDispatcher:addEventListenerWithSceneGraphPriority(touchListener, layer)
local positions = {}
local spSize = sp:getContentSize()
positions[1] = cc.p(0, spSize.height)
positions[2] = cc.p(spSize.width, spSize.height)
positions[3] = cc.p(spSize.width, 0)
positions[4] = cc.p(0,0)
debugForNormalSprite:drawPoints(positions, 4, 8, cc.c4f(0.0,1.0,1.0,1.0))
debugForNormalSprite:drawLine(positions[1], positions[2], cc.c4f(0.0,1.0,0.0,1.0))
debugForNormalSprite:drawLine(positions[2], positions[3], cc.c4f(0.0,1.0,0.0,1.0))
debugForNormalSprite:drawLine(positions[3], positions[4], cc.c4f(0.0,1.0,0.0,1.0))
debugForNormalSprite:drawLine(positions[4], positions[1], cc.c4f(0.0,1.0,0.0,1.0))
debugForNormalSprite:drawLine(positions[1], positions[3], cc.c4f(0.0,1.0,0.0,1.0))
debugForNormalSprite:setVisible(false)
local ttfConfig = {}
ttfConfig.fontFilePath = "fonts/arial.ttf"
ttfConfig.fontSize = 8
local temp = "Sprite:\nPixels drawn: ".. spSize.width*spSize.height
local spArea = cc.Label:createWithTTF(ttfConfig, temp)
sp:addChild(spArea)
spArea:setAnchorPoint(cc.p(0,1))
temp = "SpritePolygon:\nPixels drawn: "
local vertCount = "\nverts:" .. spp:getVertCount()
local sppArea = cc.Label:createWithTTF(ttfConfig, temp .. spp:getArea() .. vertCount)
spp:addChild(sppArea)
sppArea:setAnchorPoint(cc.p(0,1))
Helper.initWithLayer(layer)
Helper.titleLabel:setString(layer:title())
Helper.subtitleLabel:setString(layer:subtitle())
local function onNodeEvent(event)
if "enter" == event then
layer:onEnter()
elseif "exit" == event then
layer:onExit()
end
end
layer:registerScriptHandler(onNodeEvent)
end
----------------------------------------
----SpritePolygonTest1
----------------------------------------
local SpritePolygonTest1 = class("SpritePolygonTest1", function ()
local layer = cc.Layer:create()
return layer
end)
function SpritePolygonTest1:ctor()
cc.SpritePolygonCache:getInstance():removeAllSpritePolygonCache()
local spp = ccexp.SpritePolygon:create(imageFileName)
cc.Director:getInstance():setClearColor(cc.c4f(102.0/255, 184.0/255, 204.0/255, 255.0))
self:addChild(spp)
local s = cc.Director:getInstance():getWinSize()
local offset = cc.p(0.15 * s.width, 0)
spp:setPosition(s.width/2 + 0.15 * s.width, s.height/2)
local sp = cc.Sprite:create(imageFileName)
self:addChild(sp)
sp:setPosition(s.width/2 - 0.15 * s.width, s.height/2)
local debugForNormalSprite = cc.DrawNode:create()
sp:addChild(debugForNormalSprite)
local touchListener = cc.EventListenerTouchOneByOne:create()
touchListener:registerScriptHandler(function (touch, event)
spp:showDebug(true)
debugForNormalSprite:setVisible(true)
return true
end,cc.Handler.EVENT_TOUCH_BEGAN)
touchListener:registerScriptHandler(function (touch, event)
local pos = touch:getDelta()
local newScale = cc.clampf(spp:getScale()+pos.x*0.01, 0.1, 2)
spp:setScale(newScale)
sp:setScale(newScale)
end,cc.Handler.EVENT_TOUCH_MOVED)
touchListener:registerScriptHandler(function (touch, event)
spp:showDebug(false)
debugForNormalSprite:setVisible(false)
end,cc.Handler.EVENT_TOUCH_ENDED)
local eventDispatcher = self:getEventDispatcher()
eventDispatcher:addEventListenerWithSceneGraphPriority(touchListener, self)
local positions = {}
local spSize = sp:getContentSize()
positions[1] = cc.p(0, spSize.height)
positions[2] = cc.p(spSize.width, spSize.height)
positions[3] = cc.p(spSize.width, 0)
positions[4] = cc.p(0,0)
debugForNormalSprite:drawPoints(positions, 4, 8, cc.c4f(0.0,1.0,1.0,1.0))
debugForNormalSprite:drawLine(positions[1], positions[2], cc.c4f(0.0,1.0,0.0,1.0))
debugForNormalSprite:drawLine(positions[2], positions[3], cc.c4f(0.0,1.0,0.0,1.0))
debugForNormalSprite:drawLine(positions[3], positions[4], cc.c4f(0.0,1.0,0.0,1.0))
debugForNormalSprite:drawLine(positions[4], positions[1], cc.c4f(0.0,1.0,0.0,1.0))
debugForNormalSprite:drawLine(positions[1], positions[3], cc.c4f(0.0,1.0,0.0,1.0))
debugForNormalSprite:setVisible(false)
local ttfConfig = {}
ttfConfig.fontFilePath = "fonts/arial.ttf"
ttfConfig.fontSize = 8
local temp = "Sprite:\nPixels drawn: ".. spSize.width*spSize.height
local spArea = cc.Label:createWithTTF(ttfConfig, temp)
sp:addChild(spArea)
spArea:setAnchorPoint(cc.p(0,1))
temp = "SpritePolygon:\nPixels drawn: "
local vertCount = "\nverts:" .. spp:getVertCount()
local sppArea = cc.Label:createWithTTF(ttfConfig, temp .. spp:getArea() .. vertCount)
spp:addChild(sppArea)
sppArea:setAnchorPoint(cc.p(0,1))
Helper.initWithLayer(self)
Helper.titleLabel:setString(self:title())
Helper.subtitleLabel:setString(self:subtitle())
local function onNodeEvent(event)
if "enter" == event then
self:onEnter()
elseif "exit" == event then
self:onExit()
end
end
self:registerScriptHandler(onNodeEvent)
end
function SpritePolygonTest1:title()
return "SpritePolygon Creation"
end
function SpritePolygonTest1:subtitle()
return "SpritePolygon:create(\"Images/grossini.png\")"
end
function SpritePolygonTest1:onEnter()
cc.Director:getInstance():setClearColor(cc.c4f(102.0/255, 184.0/255, 204.0/255, 255.0))
end
function SpritePolygonTest1:onExit()
cc.Director:getInstance():setClearColor(cc.c4f(0.0, 0.0, 0.0, 1.0))
end
----------------------------------------
----SpritePolygonTest2
----------------------------------------
local SpritePolygonTest2 = class("SpritePolygonTest2", function ()
local layer = cc.Layer:create()
return layer
end)
function SpritePolygonTest2:ctor()
local verts = {}
verts[1]= cc.p(36.5, 242.0-128.5)
verts[2]= cc.p(27.5, 242.0-133.5)
verts[3]= cc.p(24.5, 242.0-145.5)
verts[4]= cc.p(26.5, 242.0-161.5)
verts[5]= cc.p(33.5, 242.0-168.5)
verts[6]= cc.p(27.5, 242.0-168.5)
verts[7]= cc.p(16.5, 242.0-179.5)
verts[8]= cc.p(30.5, 242.0-197.5)
verts[9]= cc.p(28.5, 242.0-237.5)
verts[10]= cc.p(56.5, 242.0-237.5)
verts[11]= cc.p(54.5, 242.0-197.5)
verts[12]= cc.p(68.5, 242.0-184.5)
verts[13]= cc.p(57.5, 242.0-168.5)
verts[14]= cc.p(51.5, 242.0-168.5)
verts[15]= cc.p(60.5, 242.0-154.5)
verts[16]= cc.p(57.5, 242.0-133.5)
verts[17]= cc.p(48.5, 242.0-127.5)
verts[18]= cc.p(36.5, 242.0-127.5)
cc.SpritePolygonCache:getInstance():removeAllSpritePolygonCache()
local s = ccexp.SpritePolygon:create(imageFileName, verts)
initDefaultSprite(imageFileName, s, self)
end
function SpritePolygonTest2:title()
return "SpritePolygon Creation"
end
function SpritePolygonTest2:subtitle()
return "SpritePolygon:create(\"Images/grossini.png\", verts)"
end
function SpritePolygonTest2:onEnter()
cc.Director:getInstance():setClearColor(cc.c4f(102.0/255, 184.0/255, 204.0/255, 255.0))
end
function SpritePolygonTest2:onExit()
cc.Director:getInstance():setClearColor(cc.c4f(0.0, 0.0, 0.0, 1.0))
end
----------------------------------------
----SpritePolygonTest3
----------------------------------------
local SpritePolygonTest3 = class("SpritePolygonTest3", function ()
local layer = cc.Layer:create()
return layer
end)
function SpritePolygonTest3:ctor()
local verts = {}
verts[1] = cc.p(33.500000, 73.500000)
verts[2] = cc.p(27.500000, 73.500000)
verts[3] = cc.p(16.500000, 62.500000)
verts[4] = cc.p(30.500000, 44.500000)
verts[5] = cc.p(54.500000, 44.500000)
verts[6] = cc.p(51.500000, 73.500000)
verts[7] = cc.p(60.500000, 87.500000)
verts[8] = cc.p(26.500000, 80.500000)
verts[9] = cc.p(24.500000, 96.500000)
verts[10] = cc.p(57.500000, 108.500000)
verts[11] = cc.p(36.500000, 113.500000)
verts[12] = cc.p(48.500000, 114.500000)
verts[13] = cc.p(36.500000, 114.500000)
verts[14] = cc.p(27.500000, 108.500000)
verts[15] = cc.p(68.500000, 57.500000)
verts[16] = cc.p(57.500000, 73.500000)
verts[17] = cc.p(56.500000, 4.500000)
verts[18] = cc.p(28.500000, 4.500000)
local indices = {0, 1, 2, 3, 0, 2, 4, 0, 3, 5, 0, 4, 5, 6, 0, 0, 6, 7, 8, 7, 6, 6, 9, 8, 9, 10, 8, 9, 11, 10, 11, 12, 10, 8, 10, 13, 14, 5, 4, 15, 5, 14, 4, 3, 16, 3, 17, 16}
cc.SpritePolygonCache:getInstance():removeAllSpritePolygonCache()
local s = ccexp.SpritePolygon:create(imageFileName, verts, indices)
initDefaultSprite(imageFileName, s, self)
end
function SpritePolygonTest3:title()
return "SpritePolygon Creation"
end
function SpritePolygonTest3:subtitle()
return "SpritePolygon::create(\"Images/grossini.png\", verts, indices)"
end
function SpritePolygonTest3:onEnter()
cc.Director:getInstance():setClearColor(cc.c4f(102.0/255, 184.0/255, 204.0/255, 255.0))
end
function SpritePolygonTest3:onExit()
cc.Director:getInstance():setClearColor(cc.c4f(0.0, 0.0, 0.0, 1.0))
end
----------------------------------------
----SpritePolygonTest4
----------------------------------------
local SpritePolygonTest4 = class("SpritePolygonTest4", function ()
local layer = cc.Layer:create()
return layer
end)
function SpritePolygonTest4:ctor()
local poss = {
cc.vec3(33.500000, 73.500000,0),
cc.vec3(27.500000, 73.500000,0),
cc.vec3(16.500000, 62.500000,0),
cc.vec3(30.500000, 44.500000,0),
cc.vec3(54.500000, 44.500000,0),
cc.vec3(51.500000, 73.500000,0),
cc.vec3(60.500000, 87.500000,0),
cc.vec3(26.500000, 80.500000,0),
cc.vec3(24.500000, 96.500000,0),
cc.vec3(57.500000, 108.500000,0),
cc.vec3(36.500000, 113.500000,0),
cc.vec3(48.500000, 114.500000,0),
cc.vec3(36.500000, 114.500000,0),
cc.vec3(27.500000, 108.500000,0),
cc.vec3(68.500000, 57.500000,0),
cc.vec3(57.500000, 73.500000,0),
cc.vec3(56.500000, 4.500000,0),
cc.vec3(28.500000, 4.50000, 0),
}
local indices = {0, 1, 2, 3, 0, 2, 4, 0, 3, 5, 0, 4, 5, 6, 0, 0, 6, 7, 8, 7, 6, 6, 9, 8, 9, 10, 8, 9, 11, 10, 11, 12, 10, 8, 10, 13, 14, 5, 4, 15, 5, 14, 4, 3, 16, 3, 17, 16}
local t2f = {
cc.tex2F(0.394118, 0.392562),
cc.tex2F(0.323529, 0.392562),
cc.tex2F(0.194118, 0.483471),
cc.tex2F(0.358824, 0.632231),
cc.tex2F(0.641176, 0.632231),
cc.tex2F(0.605882, 0.392562),
cc.tex2F(0.711765, 0.276859),
cc.tex2F(0.311765, 0.334711),
cc.tex2F(0.288235, 0.202479),
cc.tex2F(0.676471, 0.103306),
cc.tex2F(0.429412, 0.061983),
cc.tex2F(0.570588, 0.053719),
cc.tex2F(0.429412, 0.053719),
cc.tex2F(0.323529, 0.103306),
cc.tex2F(0.805882, 0.524793),
cc.tex2F(0.676471, 0.392562),
cc.tex2F(0.664706, 0.962810),
cc.tex2F(0.335294, 0.962810),
}
local v3f_c4b_t2f_table = {
{ vertices = poss[1], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[1]},
{ vertices = poss[2], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[2]},
{ vertices = poss[3], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[3]},
{ vertices = poss[4], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[4]},
{ vertices = poss[5], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[5]},
{ vertices = poss[6], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[6]},
{ vertices = poss[7], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[7]},
{ vertices = poss[8], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[8]},
{ vertices = poss[9], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[9]},
{ vertices = poss[10], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[10]},
{ vertices = poss[11], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[11]},
{ vertices = poss[12], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[12]},
{ vertices = poss[13], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[13]},
{ vertices = poss[14], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[14]},
{ vertices = poss[15], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[15]},
{ vertices = poss[16], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[16]},
{ vertices = poss[17], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[17]},
{ vertices = poss[18], colors = cc.c4b(255, 255, 255, 255), texCoords = t2f[18]},
}
cc.SpritePolygonCache:getInstance():removeAllSpritePolygonCache()
local s = ccexp.SpritePolygon:create(imageFileName, v3f_c4b_t2f_table, indices)
initDefaultSprite(imageFileName, s, self)
end
function SpritePolygonTest4:title()
return "SpritePolygon Creation"
end
function SpritePolygonTest4:subtitle()
return "SpritePolygon::create(\"Images/grossini.png\", vector<V3F_C4B_T2F> v, vector<unsigned short> indices)"
end
function SpritePolygonTest4:onEnter()
cc.Director:getInstance():setClearColor(cc.c4f(102.0/255, 184.0/255, 204.0/255, 255.0))
end
function SpritePolygonTest4:onExit()
cc.Director:getInstance():setClearColor(cc.c4f(0.0, 0.0, 0.0, 1.0))
end
function SpritePolygonTest()
local scene = cc.Scene:create()
Helper.createFunctionTable =
{
SpritePolygonTest1.create,
SpritePolygonTest2.create,
SpritePolygonTest3.create,
SpritePolygonTest4.create,
}
scene:addChild(SpritePolygonTest1.create())
scene:addChild(CreateBackMenuItem())
return scene
end

View File

@ -59,6 +59,7 @@ require "FastTiledMapTest/FastTiledMapTest"
require "NewAudioEngineTest/NewAudioEngineTest"
require "CocosStudio3DTest/CocosStudio3DTest"
require "WebViewTest/WebViewTest"
require "SpritePolygonTest/SpritePolygonTest"
local LINE_SPACE = 40
@ -127,6 +128,7 @@ local _allTests = {
{ isSupported = true, name = "Sprite3DTest" , create_func = Sprite3DTest },
{ isSupported = true, name = "TerrainTest" , create_func = TerrainTest },
{ isSupported = true, name = "SpriteTest" , create_func = SpriteTest },
{ isSupported = true, name = "SpritePolygonTest" , create_func = SpritePolygonTest },
{ isSupported = false, name = "TextInputTest" , create_func= TextInputTestMain },
{ isSupported = true, name = "Texture2DTest" , create_func = Texture2dTestMain },
{ isSupported = false, name = "TextureCacheTest" , create_func= TextureCacheTestMain },

View File

@ -22,11 +22,11 @@ cxxgenerator_headers =
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s
# what headers to parse
headers = %(cocosdir)s/cocos/cocos2d.h %(cocosdir)s/cocos/2d/CCProtectedNode.h %(cocosdir)s/cocos/base/CCAsyncTaskPool.h
headers = %(cocosdir)s/cocos/cocos2d.h %(cocosdir)s/cocos/2d/CCProtectedNode.h %(cocosdir)s/cocos/base/CCAsyncTaskPool.h %(cocosdir)s/cocos/2d/SpritePolygonCache.h
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^Menu*$".
classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* .*TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Ref$ UserDefault GLViewImpl GLView Image Event(?!.*(Physics).*).* Component ProtectedNode Console GLProgramCache GLProgramState Device ClippingRectangleNode .*Light$ AsyncTaskPool
classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* .*TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Ref$ UserDefault GLViewImpl GLView Image Event(?!.*(Physics).*).* Component ProtectedNode Console GLProgramCache GLProgramState Device ClippingRectangleNode .*Light$ AsyncTaskPool SpritePolygonCache
# what should we skip? in the format ClassName::[function function]
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
@ -136,7 +136,8 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS
Bone3D::[*],
Device::[getTextureDataForText],
BillBoard::[*],
Camera::[unproject]
Camera::[unproject],
SpritePolygonCache::[addSpritePolygonCache getSpritePolygonCache]
rename_functions = SpriteFrameCache::[addSpriteFramesWithFile=addSpriteFrames getSpriteFrameByName=getSpriteFrame],
ProgressTimer::[setReverseProgress=setReverseDirection],

View File

@ -23,11 +23,11 @@ cxxgenerator_headers =
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s
# what headers to parse
headers = %(cocosdir)s/cocos/2d/CCFastTMXLayer.h %(cocosdir)s/cocos/2d/CCFastTMXTiledMap.h
headers = %(cocosdir)s/cocos/2d/CCFastTMXLayer.h %(cocosdir)s/cocos/2d/CCFastTMXTiledMap.h %(cocosdir)s/cocos/2d/SpritePolygon.h
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^Menu*$".
classes = TMXLayer TMXTiledMap
classes = TMXLayer TMXTiledMap SpritePolygon
# what should we skip? in the format ClassName::[function function]
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
@ -36,7 +36,8 @@ classes = TMXLayer TMXTiledMap
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
# functions from all classes.
skip = TMXLayer::[(g|s)etTiles getTileGIDAt]
skip = TMXLayer::[(g|s)etTiles getTileGIDAt],
SpritePolygon::[create initWithVerts initWithRect initWithPoly2tri initWithMarching]
rename_functions =