diff --git a/AUTHORS b/AUTHORS index 9c43864ffb..0f9ee1b0bf 100644 --- a/AUTHORS +++ b/AUTHORS @@ -820,6 +820,7 @@ Developers: aeonmine Fixed ActionObject memory leak in ActionManagerEx::initWithDictionary + Fixed memory leak in cocos studiov2.0 reader LoungeKatt Corrected a mistake of building android project in README.md diff --git a/CHANGELOG b/CHANGELOG index 30d52eb293..8945ad62b6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ cocos2d-x-3.3 ?? [NEW] Vec2: added greater than operator + [FIX] Button: when the dimension of button title is larger than the button, button will scale to fit the dimension of the button title [FIX] Button: when the dimension of button title is larger than the button, button will scale to fit the dimension of the button title [FIX] Camera: does not work correctly when the up is not (0, 1, 0) [FIX] Cocos console: compile failure on windows if using VS express version @@ -9,7 +10,8 @@ cocos2d-x-3.3 ?? [FIX] GLProgramState: enabled GLProgramState restoring on render recreated on WP8 [FIX] Label: label shifting when outline feature enabled [FIX] Label: when applying additionalKerning to a Label that displays a string with only 1 character, the character is shifted - [FIX] Button: when the dimension of button title is larger than the button, button will scale to fit the dimension of the button title + [FIX] Scale9Sprite: will be flipped if both flipX and flipY are false + [FIX] Scale9Sprite: if scale and flip property are set at the same time, the result would be wrong. [FIX] Sprite3D: did not create attached sprite from cache [FIX] WP/WinRT: Windows 8.1 universal app support; `UIEditBox` support diff --git a/build/android-build.py b/build/android-build.py index 3465d37d8c..0376e02b65 100755 --- a/build/android-build.py +++ b/build/android-build.py @@ -15,15 +15,8 @@ def get_num_of_cpu(): ''' The build process can be accelerated by running multiple concurrent job processes using the -j-option. ''' try: - platform = sys.platform - if platform == 'win32': - if 'NUMBER_OF_PROCESSORS' in os.environ: - return int(os.environ['NUMBER_OF_PROCESSORS']) - else: - return 1 - else: - from numpy.distutils import cpuinfo - return cpuinfo.cpu._getNCPUs() + import multiprocessing + return multiprocessing.cpu_count() except Exception: print "Can't know cpuinfo, use default 1 cpu" return 1 diff --git a/cocos/2d/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp index 894927f5ae..9c9b5599e9 100644 --- a/cocos/2d/CCDrawNode.cpp +++ b/cocos/2d/CCDrawNode.cpp @@ -348,6 +348,7 @@ void DrawNode::onDraw(const Mat4 &transform, uint32_t flags) } glDrawArrays(GL_TRIANGLES, 0, _bufferCount); + glBindBuffer(GL_ARRAY_BUFFER, 0); CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, _bufferCount); CHECK_GL_ERROR_DEBUG(); @@ -382,6 +383,7 @@ void DrawNode::onDrawGLLine(const Mat4 &transform, uint32_t flags) } glLineWidth(2); glDrawArrays(GL_LINES, 0, _bufferCountGLLine); + glBindBuffer(GL_ARRAY_BUFFER, 0); CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCountGLLine); CHECK_GL_ERROR_DEBUG(); @@ -418,6 +420,7 @@ void DrawNode::onDrawGLPoint(const Mat4 &transform, uint32_t flags) } glDrawArrays(GL_POINTS, 0, _bufferCountGLPoint); + glBindBuffer(GL_ARRAY_BUFFER, 0); CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCountGLPoint); CHECK_GL_ERROR_DEBUG(); diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp index a9a2f0c593..cb38bab2fd 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp @@ -733,11 +733,15 @@ ActionTimeline* ActionTimelineCache::loadAnimationActionWithFileFromXML(const st // xml read std::string fullpath = FileUtils::getInstance()->fullPathForFilename(fileName).c_str(); ssize_t size; - std::string content =(char*)FileUtils::getInstance()->getFileData(fullpath, "r", &size); + + //fix memory leak for v3.3 + unsigned char* pByte = FileUtils::getInstance()->getFileData(fullpath, "r", &size); // xml parse tinyxml2::XMLDocument* document = new tinyxml2::XMLDocument(); - document->Parse(content.c_str()); + document->Parse((const char*)pByte); + + free(pByte); const tinyxml2::XMLElement* rootElement = document->RootElement();// Root CCLOG("rootElement name = %s", rootElement->Name()); diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp index 97398eb3f6..206847d592 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp @@ -449,7 +449,8 @@ void CSLoader::initNode(Node* node, const rapidjson::Value& json) Node* CSLoader::loadSimpleNode(const rapidjson::Value& json) { Node* node = Node::create(); - node->retain(); + // fix memory leak for v3.3 + //node->retain(); initNode(node, json); return node; @@ -468,8 +469,8 @@ Node* CSLoader::loadSubGraph(const rapidjson::Value& json) { node = Node::create(); } - - node->retain(); + // fix memory leak for v3.3 + //node->retain(); initNode(node, json); @@ -507,7 +508,8 @@ Node* CSLoader::loadSprite(const rapidjson::Value& json) sprite = Sprite::create(); } - sprite->retain(); + // fix memory leak for v3.3 + //sprite->retain(); initNode(sprite, json); @@ -529,7 +531,8 @@ Node* CSLoader::loadParticle(const rapidjson::Value& json) ParticleSystemQuad* particle = ParticleSystemQuad::create(filePath); particle->setTotalParticles(num); - particle->retain(); + // fix memory leak for v3.3 + //particle->retain(); initNode(particle, json); @@ -578,7 +581,8 @@ Node* CSLoader::loadWidget(const rapidjson::Value& json) std::string guiClassName = getGUIClassName(classname); widget = dynamic_cast(ObjectFactory::getInstance()->createObject(guiClassName)); - widget->retain(); + // fix memory leak for v3.3 + //widget->retain(); WidgetReaderProtocol* reader = dynamic_cast(ObjectFactory::getInstance()->createObject(readerName)); @@ -587,7 +591,9 @@ Node* CSLoader::loadWidget(const rapidjson::Value& json) else if (isCustomWidget(classname)) { widget = dynamic_cast(ObjectFactory::getInstance()->createObject(classname)); - widget->retain(); + + //fix memory leak for v3.3 + //widget->retain(); // // 1st., custom widget parse properties of parent widget with parent widget reader @@ -826,7 +832,8 @@ Node* CSLoader::nodeFromProtocolBuffers(const protocolbuffers::NodeTree &nodetre readerName.append("Reader"); Widget* widget = dynamic_cast(ObjectFactory::getInstance()->createObject(guiClassName)); - widget->retain(); + //fix memory leak for v3.3 + //widget->retain(); WidgetReaderProtocol* reader = dynamic_cast(ObjectFactory::getInstance()->createObject(readerName)); reader->setPropsFromProtocolBuffers(widget, nodetree); @@ -840,7 +847,9 @@ Node* CSLoader::nodeFromProtocolBuffers(const protocolbuffers::NodeTree &nodetre else if (isCustomWidget(classname)) { Widget* widget = dynamic_cast(ObjectFactory::getInstance()->createObject(classname)); - widget->retain(); + + //fix memory leak for v3.3 + //widget->retain(); // // 1st., custom widget parse properties of parent widget with parent widget reader @@ -1046,8 +1055,8 @@ void CSLoader::setPropsForSpriteFromProtocolBuffers(cocos2d::Node *node, CCLOG("filePath is empty. Create a sprite with no texture"); } */ - - sprite->retain(); + //fix memory leak for v3.3 + //sprite->retain(); setPropsForNodeFromProtocolBuffers(sprite, nodeOptions); @@ -1245,11 +1254,15 @@ Node* CSLoader::nodeFromXMLFile(const std::string &fileName) // xml read std::string fullpath = FileUtils::getInstance()->fullPathForFilename(fileName).c_str(); ssize_t size; - std::string content =(char*)FileUtils::getInstance()->getFileData(fullpath, "r", &size); + + //fix memory leak for v3.3 + unsigned char* pByte = FileUtils::getInstance()->getFileData(fullpath, "r", &size); // xml parse tinyxml2::XMLDocument* document = new tinyxml2::XMLDocument(); - document->Parse(content.c_str()); + document->Parse((const char*)pByte); + + free(pByte); const tinyxml2::XMLElement* rootElement = document->RootElement();// Root CCLOG("rootElement name = %s", rootElement->Name()); @@ -1408,7 +1421,9 @@ Node* CSLoader::nodeFromXML(const tinyxml2::XMLElement *objectData, const std::s readerName.append("Reader"); Widget* widget = dynamic_cast(ObjectFactory::getInstance()->createObject(guiClassName)); - widget->retain(); + + //fix memory leak for v3.3 + //widget->retain(); WidgetReaderProtocol* reader = dynamic_cast(ObjectFactory::getInstance()->createObject(readerName)); reader->setPropsFromXML(widget, objectData); diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp index cc8cc328c4..36b1e6326b 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp @@ -330,7 +330,7 @@ void DataReaderHelper::addDataFromFile(const std::string& filePath) DataReaderHelper::addDataFromBinaryCache(contentStr.c_str(),&dataInfo); } - CC_SAFE_DELETE_ARRAY(pBytes); + free(pBytes); } void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const std::string& plistPath, const std::string& filePath, Ref *target, SEL_SCHEDULE selector) @@ -429,7 +429,9 @@ void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const Data bytecpy; bytecpy.copy(pBytes, size); data->fileContent = std::string((const char*)bytecpy.getBytes(), size); - CC_SAFE_DELETE_ARRAY(pBytes); + + // fix memory leak for v3.3 + free(pBytes); if (str == ".xml") { diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp index 2e2fa468d0..0c08af624a 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp @@ -163,15 +163,7 @@ namespace cocostudio label->setFontSize(fontSize); std::string fontName = options.has_fontname() ? options.fontname() : "微软雅黑"; - - std::string fontFilePath = protocolBuffersPath.append(fontName); - if (FileUtils::getInstance()->isFileExist(fontFilePath)) - { - label->setFontName(fontFilePath); - } - else{ - label->setFontName(fontName); - } + label->setFontName(fontName); bool aw = options.has_areawidth(); bool ah = options.has_areaheight(); diff --git a/cocos/platform/linux/CCFileUtils-linux.cpp b/cocos/platform/linux/CCFileUtils-linux.cpp index a1c047b5bd..70136decd9 100644 --- a/cocos/platform/linux/CCFileUtils-linux.cpp +++ b/cocos/platform/linux/CCFileUtils-linux.cpp @@ -36,6 +36,10 @@ THE SOFTWARE. #include #include +#ifndef CC_RESOURCE_FOLDER_LINUX +#define CC_RESOURCE_FOLDER_LINUX ("/Resources/") +#endif + using namespace std; NS_CC_BEGIN @@ -71,7 +75,7 @@ bool FileUtilsLinux::init() fullpath[length] = '\0'; std::string appPath = fullpath; _defaultResRootPath = appPath.substr(0, appPath.find_last_of("/")); - _defaultResRootPath += "/Resources/"; + _defaultResRootPath += CC_RESOURCE_FOLDER_LINUX; // Set writable path to $XDG_CONFIG_HOME or ~/.config// if $XDG_CONFIG_HOME not exists. const char* xdg_config_path = getenv("XDG_CONFIG_HOME"); diff --git a/cocos/renderer/CCGLProgramCache.cpp b/cocos/renderer/CCGLProgramCache.cpp index f8bb1a3d55..1626bc30d9 100644 --- a/cocos/renderer/CCGLProgramCache.cpp +++ b/cocos/renderer/CCGLProgramCache.cpp @@ -439,7 +439,7 @@ GLProgram* GLProgramCache::getGLProgram(const std::string &key) void GLProgramCache::addGLProgram(GLProgram* program, const std::string &key) { // release old one - auto prev = getProgram(key); + auto prev = getGLProgram(key); if( prev == program ) return; @@ -447,17 +447,21 @@ void GLProgramCache::addGLProgram(GLProgram* program, const std::string &key) CC_SAFE_RELEASE_NULL(prev); if (program) - program->retain(); + program->retain(); _programs[key] = program; } std::string GLProgramCache::getShaderMacrosForLight() const { GLchar def[256]; - sprintf(def, "\n#define MAX_DIRECTIONAL_LIGHT_NUM %d \n" + auto conf = Configuration::getInstance(); + + snprintf(def, sizeof(def)-1, "\n#define MAX_DIRECTIONAL_LIGHT_NUM %d \n" "\n#define MAX_POINT_LIGHT_NUM %d \n" - "\n#define MAX_SPOT_LIGHT_NUM %d \n" - , Configuration::getInstance()->getMaxSupportDirLightInShader(), Configuration::getInstance()->getMaxSupportPointLightInShader(), Configuration::getInstance()->getMaxSupportSpotLightInShader()); + "\n#define MAX_SPOT_LIGHT_NUM %d \n", + conf->getMaxSupportDirLightInShader(), + conf->getMaxSupportPointLightInShader(), + conf->getMaxSupportSpotLightInShader()); return std::string(def); } diff --git a/cocos/scripting/lua-bindings/auto/api/Scale9Sprite.lua b/cocos/scripting/lua-bindings/auto/api/Scale9Sprite.lua index c261634a7d..428fd4194d 100644 --- a/cocos/scripting/lua-bindings/auto/api/Scale9Sprite.lua +++ b/cocos/scripting/lua-bindings/auto/api/Scale9Sprite.lua @@ -259,6 +259,30 @@ -- @param self -- @param #vec2_table anchorPoint +-------------------------------- +-- +-- @function [parent=#Scale9Sprite] setScaleY +-- @param self +-- @param #float scaleY + +-------------------------------- +-- +-- @function [parent=#Scale9Sprite] setScaleX +-- @param self +-- @param #float scaleX + +-------------------------------- +-- +-- @function [parent=#Scale9Sprite] getScaleY +-- @param self +-- @return float#float ret (return value: float) + +-------------------------------- +-- +-- @function [parent=#Scale9Sprite] getScaleX +-- @param self +-- @return float#float ret (return value: float) + -------------------------------- -- -- @function [parent=#Scale9Sprite] updateDisplayedOpacity @@ -270,6 +294,14 @@ -- @function [parent=#Scale9Sprite] cleanup -- @param self +-------------------------------- +-- @overload self, float, float +-- @overload self, float +-- @function [parent=#Scale9Sprite] setScale +-- @param self +-- @param #float scalex +-- @param #float scaley + -------------------------------- -- -- @function [parent=#Scale9Sprite] updateDisplayedColor @@ -282,6 +314,12 @@ -- @param self -- @param #size_table size +-------------------------------- +-- +-- @function [parent=#Scale9Sprite] getScale +-- @param self +-- @return float#float ret (return value: float) + -------------------------------- -- js ctor -- @function [parent=#Scale9Sprite] Scale9Sprite diff --git a/cocos/scripting/lua-bindings/auto/api/Sprite3D.lua b/cocos/scripting/lua-bindings/auto/api/Sprite3D.lua index 9af5be0a63..b1e8971886 100644 --- a/cocos/scripting/lua-bindings/auto/api/Sprite3D.lua +++ b/cocos/scripting/lua-bindings/auto/api/Sprite3D.lua @@ -34,6 +34,12 @@ -- @param self -- @return Mesh#Mesh ret (return value: cc.Mesh) +-------------------------------- +-- +-- @function [parent=#Sprite3D] setCullFace +-- @param self +-- @param #unsigned int cullFace + -------------------------------- -- light mask getter & setter, light works only when _lightmask & light's flag is true, default value of _lightmask is 0xffff -- @function [parent=#Sprite3D] setLightMask @@ -60,30 +66,24 @@ -------------------------------- -- --- @function [parent=#Sprite3D] setCullFace +-- @function [parent=#Sprite3D] getSkeleton -- @param self --- @param #unsigned int cullFace +-- @return Skeleton3D#Skeleton3D ret (return value: cc.Skeleton3D) -------------------------------- --- get SubMeshState by index +-- get Mesh by index -- @function [parent=#Sprite3D] getMeshByIndex -- @param self -- @param #int index -- @return Mesh#Mesh ret (return value: cc.Mesh) -------------------------------- --- get SubMeshState by Name +-- get Mesh by Name, it returns the first one if there are more than one mesh with the same name -- @function [parent=#Sprite3D] getMeshByName -- @param self -- @param #string name -- @return Mesh#Mesh ret (return value: cc.Mesh) --------------------------------- --- --- @function [parent=#Sprite3D] getSkeleton --- @param self --- @return Skeleton3D#Skeleton3D ret (return value: cc.Skeleton3D) - -------------------------------- -- get AttachNode by bone name, return nullptr if not exist -- @function [parent=#Sprite3D] getAttachNode diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_3d_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_3d_auto.cpp index 4e5e2095a1..98cc4521d1 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_3d_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_3d_auto.cpp @@ -580,6 +580,52 @@ int lua_cocos2dx_3d_Sprite3D_getMesh(lua_State* tolua_S) return 0; } +int lua_cocos2dx_3d_Sprite3D_setCullFace(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::Sprite3D* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.Sprite3D",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::Sprite3D*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_3d_Sprite3D_setCullFace'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + unsigned int arg0; + + ok &= luaval_to_uint32(tolua_S, 2,&arg0, "cc.Sprite3D:setCullFace"); + if(!ok) + return 0; + cobj->setCullFace(arg0); + return 0; + } + CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.Sprite3D:setCullFace",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_3d_Sprite3D_setCullFace'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_3d_Sprite3D_setLightMask(lua_State* tolua_S) { int argc = 0; @@ -760,7 +806,7 @@ int lua_cocos2dx_3d_Sprite3D_removeAttachNode(lua_State* tolua_S) return 0; } -int lua_cocos2dx_3d_Sprite3D_setCullFace(lua_State* tolua_S) +int lua_cocos2dx_3d_Sprite3D_getSkeleton(lua_State* tolua_S) { int argc = 0; cocos2d::Sprite3D* cobj = nullptr; @@ -780,28 +826,26 @@ int lua_cocos2dx_3d_Sprite3D_setCullFace(lua_State* tolua_S) #if COCOS2D_DEBUG >= 1 if (!cobj) { - tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_3d_Sprite3D_setCullFace'", nullptr); + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_3d_Sprite3D_getSkeleton'", nullptr); return 0; } #endif argc = lua_gettop(tolua_S)-1; - if (argc == 1) + if (argc == 0) { - unsigned int arg0; - - ok &= luaval_to_uint32(tolua_S, 2,&arg0, "cc.Sprite3D:setCullFace"); if(!ok) return 0; - cobj->setCullFace(arg0); - return 0; + cocos2d::Skeleton3D* ret = cobj->getSkeleton(); + object_to_luaval(tolua_S, "cc.Skeleton3D",(cocos2d::Skeleton3D*)ret); + return 1; } - CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.Sprite3D:setCullFace",argc, 1); + CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.Sprite3D:getSkeleton",argc, 0); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_3d_Sprite3D_setCullFace'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_3d_Sprite3D_getSkeleton'.",&tolua_err); #endif return 0; @@ -900,50 +944,6 @@ int lua_cocos2dx_3d_Sprite3D_getMeshByName(lua_State* tolua_S) return 0; } -int lua_cocos2dx_3d_Sprite3D_getSkeleton(lua_State* tolua_S) -{ - int argc = 0; - cocos2d::Sprite3D* cobj = nullptr; - bool ok = true; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"cc.Sprite3D",0,&tolua_err)) goto tolua_lerror; -#endif - - cobj = (cocos2d::Sprite3D*)tolua_tousertype(tolua_S,1,0); - -#if COCOS2D_DEBUG >= 1 - if (!cobj) - { - tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_3d_Sprite3D_getSkeleton'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - return 0; - cocos2d::Skeleton3D* ret = cobj->getSkeleton(); - object_to_luaval(tolua_S, "cc.Skeleton3D",(cocos2d::Skeleton3D*)ret); - return 1; - } - CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.Sprite3D:getSkeleton",argc, 0); - return 0; - -#if COCOS2D_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_3d_Sprite3D_getSkeleton'.",&tolua_err); -#endif - - return 0; -} int lua_cocos2dx_3d_Sprite3D_getAttachNode(lua_State* tolua_S) { int argc = 0; @@ -1059,14 +1059,14 @@ int lua_register_cocos2dx_3d_Sprite3D(lua_State* tolua_S) tolua_function(tolua_S,"getLightMask",lua_cocos2dx_3d_Sprite3D_getLightMask); tolua_function(tolua_S,"removeAllAttachNode",lua_cocos2dx_3d_Sprite3D_removeAllAttachNode); tolua_function(tolua_S,"getMesh",lua_cocos2dx_3d_Sprite3D_getMesh); + tolua_function(tolua_S,"setCullFace",lua_cocos2dx_3d_Sprite3D_setCullFace); tolua_function(tolua_S,"setLightMask",lua_cocos2dx_3d_Sprite3D_setLightMask); tolua_function(tolua_S,"getBlendFunc",lua_cocos2dx_3d_Sprite3D_getBlendFunc); tolua_function(tolua_S,"getMeshCount",lua_cocos2dx_3d_Sprite3D_getMeshCount); tolua_function(tolua_S,"removeAttachNode",lua_cocos2dx_3d_Sprite3D_removeAttachNode); - tolua_function(tolua_S,"setCullFace",lua_cocos2dx_3d_Sprite3D_setCullFace); + tolua_function(tolua_S,"getSkeleton",lua_cocos2dx_3d_Sprite3D_getSkeleton); tolua_function(tolua_S,"getMeshByIndex",lua_cocos2dx_3d_Sprite3D_getMeshByIndex); tolua_function(tolua_S,"getMeshByName",lua_cocos2dx_3d_Sprite3D_getMeshByName); - tolua_function(tolua_S,"getSkeleton",lua_cocos2dx_3d_Sprite3D_getSkeleton); tolua_function(tolua_S,"getAttachNode",lua_cocos2dx_3d_Sprite3D_getAttachNode); tolua_function(tolua_S,"create", lua_cocos2dx_3d_Sprite3D_create); tolua_endmodule(tolua_S); diff --git a/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp b/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp index 1933041efc..5a918d57eb 100644 --- a/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp +++ b/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp @@ -773,7 +773,7 @@ int LuaStack::luaLoadChunksFromZIP(lua_State *L) (unsigned char*)stack->_xxteaKey, (xxtea_long)stack->_xxteaKeyLen, &len); - delete []zipFileData; + free(zipFileData); zipFileData = nullptr; zip = ZipFile::createWithBuffer(buffer, len); } else { @@ -797,7 +797,7 @@ int LuaStack::luaLoadChunksFromZIP(lua_State *L) lua_setfield(L, -2, filename.c_str()); ++count; } - delete []zbuffer; + free(zbuffer); } filename = zip->getNextFilename(); } @@ -812,7 +812,7 @@ int LuaStack::luaLoadChunksFromZIP(lua_State *L) } if (zipFileData) { - delete []zipFileData; + free(zipFileData); } if (buffer) { diff --git a/cocos/scripting/lua-bindings/manual/Cocos2dxLuaLoader.cpp b/cocos/scripting/lua-bindings/manual/Cocos2dxLuaLoader.cpp index 732eed5a57..956e9b0cd7 100644 --- a/cocos/scripting/lua-bindings/manual/Cocos2dxLuaLoader.cpp +++ b/cocos/scripting/lua-bindings/manual/Cocos2dxLuaLoader.cpp @@ -108,7 +108,7 @@ extern "C" { LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->luaLoadBuffer(L, (char*)chunk, (int)chunkSize, chunkName.c_str()); - delete []chunk; + free(chunk); } else { diff --git a/cocos/ui/UILoadingBar.cpp b/cocos/ui/UILoadingBar.cpp index c480b8537d..acca094563 100644 --- a/cocos/ui/UILoadingBar.cpp +++ b/cocos/ui/UILoadingBar.cpp @@ -102,14 +102,14 @@ void LoadingBar::setDirection(cocos2d::ui::LoadingBar::Direction direction) _barRenderer->setAnchorPoint(Vec2(0.0f,0.5f)); _barRenderer->setPosition(Vec2(0,_contentSize.height*0.5f)); if (!_scale9Enabled) { - _barRenderer->setFlippedX(false); + _barRenderer->getSprite()->setFlippedX(false); } break; case Direction::RIGHT: _barRenderer->setAnchorPoint(Vec2(1.0f,0.5f)); _barRenderer->setPosition(Vec2(_totalLength,_contentSize.height*0.5f)); if (!_scale9Enabled) { - _barRenderer->setFlippedX(true); + _barRenderer->getSprite()->setFlippedX(true); } break; } diff --git a/cocos/ui/UIScale9Sprite.cpp b/cocos/ui/UIScale9Sprite.cpp index 1882f907d1..0fe1510e6b 100644 --- a/cocos/ui/UIScale9Sprite.cpp +++ b/cocos/ui/UIScale9Sprite.cpp @@ -50,6 +50,9 @@ namespace ui { , _insetTop(0) , _insetRight(0) , _insetBottom(0) + ,_flippedX(false) + ,_flippedY(false) + { this->setAnchorPoint(Vec2(0.5,0.5)); } @@ -1021,6 +1024,9 @@ y+=ytranslate; \ this->cleanupSlicedSprites(); _protectedChildren.clear(); + //we must invalide the transform when toggling scale9enabled + _transformUpdated = _transformDirty = _inverseDirty = true; + if (_scale9Enabled) { if (_scale9Image) @@ -1208,34 +1214,17 @@ y+=ytranslate; \ void Scale9Sprite::setFlippedX(bool flippedX) { + + float realScale = this->getScaleX(); _flippedX = flippedX; - if (_scale9Enabled) - { - this->setScaleX(-1); - } - else - { - if (_scale9Image) - { - _scale9Image->setFlippedX(flippedX); - } - } + this->setScaleX(realScale); } void Scale9Sprite::setFlippedY(bool flippedY) { + float realScale = this->getScaleY(); _flippedY = flippedY; - if (_scale9Enabled) - { - this->setScaleY(-1); - } - else - { - if (_scale9Image) - { - _scale9Image->setFlippedY(flippedY); - } - } + this->setScaleY(realScale); } bool Scale9Sprite::isFlippedX()const @@ -1247,4 +1236,60 @@ y+=ytranslate; \ { return _flippedY; } + + void Scale9Sprite::setScaleX(float scaleX) + { + if (_flippedX) { + scaleX = scaleX * -1; + } + Node::setScaleX(scaleX); + } + + void Scale9Sprite::setScaleY(float scaleY) + { + if (_flippedY) { + scaleY = scaleY * -1; + } + Node::setScaleY(scaleY); + } + + void Scale9Sprite::setScale(float scale) + { + this->setScaleX(scale); + this->setScaleY(scale); + this->setScaleZ(scale); + } + + void Scale9Sprite::setScale(float scaleX, float scaleY) + { + this->setScaleX(scaleX); + this->setScaleY(scaleY); + } + + float Scale9Sprite::getScaleX()const + { + float originalScale = Node::getScaleX(); + if (_flippedX) + { + originalScale = originalScale * -1.0; + } + return originalScale; + } + + float Scale9Sprite::getScaleY()const + { + float originalScale = Node::getScaleY(); + if (_flippedY) + { + originalScale = originalScale * -1.0; + } + return originalScale; + } + + float Scale9Sprite::getScale()const + { + CCASSERT(this->getScaleX() == this->getScaleY(), "Scale9Sprite#scale. ScaleX != ScaleY. Don't know which one to return"); + return this->getScaleX(); + } + }} diff --git a/cocos/ui/UIScale9Sprite.h b/cocos/ui/UIScale9Sprite.h index 19976ffef9..0923fab540 100644 --- a/cocos/ui/UIScale9Sprite.h +++ b/cocos/ui/UIScale9Sprite.h @@ -354,6 +354,16 @@ namespace ui { */ virtual bool isFlippedY()const; + //override the setScale function of Node + virtual void setScaleX(float scaleX) override; + virtual void setScaleY(float scaleY) override; + virtual void setScale(float scale) override; + virtual void setScale(float scalex, float scaley) override; + using Node::setScaleZ; + virtual float getScaleX() const override; + virtual float getScaleY() const override; + virtual float getScale() const override; + using Node::getScaleZ; protected: void updateCapInset(); void updatePositions(); diff --git a/docs/CONTRIBUTE.md b/docs/CONTRIBUTE.md new file mode 100644 index 0000000000..6df16d45fa --- /dev/null +++ b/docs/CONTRIBUTE.md @@ -0,0 +1,79 @@ +# Contributing to cocos2d-x + + +## For general questions + + +You can ask general questions by using: + +- Forum (preferred way): http://discuss.cocos2d-x.org/ +- IRC: https://webchat.freenode.net/ (Use the *cocos2d* or *cocos2d-x* channels) +- Weibo: http://t.sina.com.cn/cocos2dx +- Twitter: http://www.twitter.com/cocos2dx + +## Reporting bugs + +To report bugs, please use the [Issue Tracker](https://github.com/cocos2d/cocos2d-x/issues) + +Steps to report a bug: +* Open the [url](https://github.com/cocos2d/cocos2d-x/issues/new) +* Add all the needed information to reproduce the bug + + +## Submitting patches + +If you want to contribute code, please follow these steps: + +(If you are new to git and/or GitHub, you should read [Pro Git](http://progit.org/book/) , especially the section on [Contributing to a project:Small/Large Public Project](http://progit.org/book/ch5-2.html#public_small_project) ) + +- Download the latest cocos2d-x develop branch from github: + +``` +$ git clone git://github.com/cocos2d/cocos2d-x.git +$ cd cocos2d-x +$ git checkout v3 +$ ./download-deps.py +$ git submodule update --init +``` + +- Apply your changes in the recently downloaded repository +- Commit your changes in your own repository +- Create a new branch with your patch: `$ git checkout -b my_fix_branch` +- Push your new branch to your public repository +- Send a “pull request” to user “cocos2d” +- It must be _complete_. See the definition below +- It must follow the _Releases_ rules. See the definition below + +## Only _complete_ patches will be merged + +The patch must be _complete_. And by that, we mean: + +- Follow the [Cocos2d C++ Coding Style][1] +- Describe what the patch does +- Include test cases +- Include unit tests if applicable +- Must be tested in all supported platforms [*] +- Must NOT degrade the performance +- Must NOT break existing tests cases +- Must NOT break the Continuous Integration build +- Must NOT break backward compatibility +- Must compile WITHOUT warnings +- New APIs MUST be **easy to use**, **familiar** to cocos2d-x users +- New APIs MUST be documented using Doxgen strings +- Code MUST be **easy to extend** +- Must be efficient (fast / low memory needs) +- It must not duplicate existing code, unless the new code deprecates the old one +- Patches that refactor key components will only be merged in the next major versions. + +[*]: If you don't have access to test your code in all the supported platforms, let us know. + + +# Promoting cocos2d + +Help us promote cocos2d-x by using the cocos2d logo in your game, or by mentioning cocos2d in the credits. + +[Logo Resources of Cocos2d-x][2] + + +[1]: https://github.com/cocos2d/cocos2d-x/blob/v3/docs/CODING_STYLE.md +[2]: http://www.cocos2d-x.org/wiki/Logo_Resources_of_Cocos2d-x diff --git a/docs/RELEASE_ENGINEERING.md b/docs/RELEASE_ENGINEERING.md new file mode 100644 index 0000000000..2fba92ad35 --- /dev/null +++ b/docs/RELEASE_ENGINEERING.md @@ -0,0 +1,171 @@ +# Cocos2d-x Release Engineering + + +## Tagging + +New releases must be tagged in github. The tag name must follow these rules: + + cocos2d-x-Major.Minor[.Status] + +or + + cocos2d-x-Major.Minor.Revision[.Status] + +Example of valid names: + +* cocos2d-x-3.0rc0 +* cocos2d-x-3.0 +* cocos2d-x-2.1.1 +* cocos2d-x-2.1.1rc0 + +See "Naming Conventions" below + +## Branching + +Each Major version will have 2 branches, `master` and `develop`. +For cocos2d-x v3, the branches names will be `v3-master` and `v3-develop`, for v4 the branches names will be `v4-master` and `v4-develop`, and so on. + +* `master` is the stable branch. +* `develop` is the unstable branch. All new features, bug fixes, etc, are applied first to `develop`. + +Once a new version is released (either Major, Minor or Revision), then `develop` branch must be merged into `master` branch. To be more specific, `master` only contains _stable_ releases. _Alpha_, _Beta_, and _RC_ versions MUST NOT be merged into `master`. + + +## Announcing + +Only stable releases must be announced on: + +* [Blog](http://www.cocos2d-x.org/news) + +All kind of releases (alpha,beta,rc, final) must be announced on: +* [Twitter](https://twitter.com/cocos2dx) +* [Forum](http://discuss.cocos2d-x.org/) + + +## Download package + +A download package must be available for each released version. +The package shall include the source code of cocos2d-x, and the needed scripts to download and install the 3rd party binaries. + + +## Release Notes and Changelog + +**BEFORE** releasing a new version (either stable or unstable), the following documents must be updated: + +* [CHANGELOG](https://github.com/cocos2d/cocos2d-x/blob/v3/CHANGELOG) +* [Release Notes](https://github.com/cocos2d/cocos2d-x/blob/v3/docs/RELEASE_NOTES.md) + +## Documentation + +**BEFORE** releasing a new Minor or Major stable release, the following tasks MUST be done: + +- All documentation MUST be updated to the new version. This includes: + - API Reference + - Programmers Guide + +## Backward compatibility + +- Minor versions MUST be backward compatible with previous minor versions. eg: v3.2 must be backward compatible with v3.1 and v3.0. +- Major versions SHOULD be backward compatible with previous major versions. Breaking backward compatibility in Major versions is acceptable only if it is extremely well justified + +## Deprecated APIs + +- Only Major versions (eg: 4.0, 5.0) can introduce deprecated APIs. Deprecated APIs cannot be introduced in Point releases (eg: 3.5, 4.2). +- Only Major versions can remove deprecated APIs. They cannot be removed in Point versions. +- A deprecated API must live at least for the whole cycle of a Major version. Eg: if an API was deprecated in 4.0, it can be removed in 5.0, but not before. It can be removed in 6.0 or future Major releases, but it cannot be removed in Point releases, like 5.1. + + +## Performance tests + +- Performance tests MUST be run before releasing a Release Candidate +- If performance is worse than previous stable version, then the Release Candidate MUST NOT be released (See Naming Conventions below) +- Results of the performance tests must be documented in this [spreadsheet](https://docs.google.com/spreadsheet/ccc?key=0AvvkdgVbWvpZdHFudzdDT3NuYTRNTHlZZzRGZWYzMmc#gid=8) + + +## Samples and tests + +**BEFORE** releasing a new Minor or Major stable release, the following tasks MUST be done: + +- All the samples and tests must be updated to use the new version. This includes: + - The samples in [cocos2d-x-samples](https://github.com/cocos2d/cocos2d-x-samples) repository + - The demo games [EarthWarrior3D](https://github.com/chukong/EarthWarrior3D) and [FantasyWarrior3D](https://github.com/chukong/FantasyWarrior3D) + - All the tests bundled in cocos2d-x + - All the templates bundled in cocos2d-x + +## Naming conventions + +### Alpha + +The product is unstable. It could have memory leaks, or crashes, or the API is unstable. The product contains little QA. +Although the product is not ready for production, the product should be testable. +Alpha versions might have Core functionality that has just been refactored, meaning that Core functionality might be unstable, but should work Ok. + +As an example, for cocos2d-x, an _Alpha_ version means: + +* Basic functionality works Ok (not great, but OK), like Sprites, Scenes, actions, etc. +_* But it might have memory leaks, or crashes, or the recently added features might be unfinished. The documentation might not be updated. +* As an example, the Renderer refactoring must be done in "alpha" versions (but not Beta versions). + +Alpha versions are NOT feature freeze. New features might be added in future alpha and beta versions. + +### Beta + +The product is more stable than _Alpha_. The product might crash, but not frequently. No major changes were made in core components. +Smaller features could be refactored in _Beta_ versions, but the core functionality is stable. +The product has more QA. +The only difference between _Alpha_ and _Beta_, is that _Beta_ is more stable than _Alpha_. And that in _Beta_ versions no new major features will be added. + +As an example, for cocos2d-x it means: + +* All the Core features (Sprites, Menu, Labels, Director, Transitions) are stable. Bug fixes could have been added into the Core functionality, but no major refactoring were done in the Core. +* But perhaps new features like the new Particle Engine could be unfinished, or the Cocos Studio reader might crash. +* Some cocos2d-x users might want to use a beta version for real games. + +Beta versions are NOT feature freeze. __Small__ new features might be added in future _Beta_ versions. New __BIG__ features that might affect the Core functionality must only be added in _Alpha_ versions, and not in _Beta_ versions. + + +### Release Candidate +Release candidate means that, unless major bugs are found, the product is ready for release. +The difference between _Release Candidate__ and _Final_ is that RC has less testing than the final version. + +Many cocos2d-x users might want to try and use the RC releases for production. + +RC versions ARE feature freeze. No new features, no matter how small they are, MUST be added in RC versions, because as the name implies, it is a _Release Candiate_. + + +### Final + +It is the new stable version. + +## Number conventions + +major.minor [revision | status] + +### Major +The major number is increased when there are significant jumps in functionality such as changing the framework which could cause incompatibility with interfacing systems + +### Minor +The minor number is incremented when only minor features or significant fixes have been added. + +### Revision +The revision number is incremented when minor bugs are fixed. + +### Status +The status could be: alphaN, betaN or rcN. + +'N' is a number, and the first MUST always be 0. + +### Examples + +v2.0-alpha0: + - New major version of cocos2d-x. + - Unstable + +v2.1.3: + - Stable version of cocos2d-x. It is the same as v2.1 plus some bug fixes. + +v2.2-beta0: + - Similar to v2.1.3, but some new features were added, but are not stable yet. + +v2.2: + - Similar to v2.1.3, but some small features were added. The new features are stable. diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index 93c78241af..d0fe91b595 100644 --- a/templates/cocos2dx_files.json +++ b/templates/cocos2dx_files.json @@ -1154,9 +1154,11 @@ "cocos/ui/proj.win32/libui.vcxproj", "cocos/ui/proj.win32/libui.vcxproj.filters", "docs/CODING_STYLE.md", + "docs/CONTRIBUTE.md", "docs/Groups.h", "docs/MainPage.h", "docs/RELEASE_NOTES.md", + "docs/RELEASING_RULES.md", "docs/cocos2dx_portrait.png", "docs/doxygen.config", "download-deps.py", diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index 935ce3fbe3..71965a0bc3 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -1114,7 +1114,7 @@ void Sprite3DReskinTest::onTouchesEnded(const std::vector& touches, Even void Sprite3DReskinTest::applyCurSkin() { for (ssize_t i = 0; i < _sprite->getMeshCount(); i++) { - auto mesh = _sprite->getMeshByIndex(i); + auto mesh = _sprite->getMeshByIndex(static_cast(i)); bool isVisible = false; for (auto& it : _curSkin) { if (mesh->getName() == it.second) @@ -1123,7 +1123,7 @@ void Sprite3DReskinTest::applyCurSkin() break; } } - _sprite->getMeshByIndex(i)->setVisible(isVisible); + _sprite->getMeshByIndex(static_cast(i))->setVisible(isVisible); } } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp index b23723e311..68530ff885 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp @@ -44,13 +44,14 @@ bool UIScale9SpriteTest::init() auto moveTo = MoveBy::create(1.0, Vec2(30,0)); auto moveBack = moveTo->reverse(); auto rotateBy = RotateBy::create(1.0, 180); - auto action = Sequence::create(moveTo,moveBack, rotateBy, NULL); + auto scaleBy = ScaleTo::create(1.0, -2.0); + auto action = Sequence::create(moveTo,moveBack, rotateBy,scaleBy, NULL); Sprite *normalSprite1 = Sprite::create("cocosui/animationbuttonnormal.png"); normalSprite1->setPosition(100, 270); -// normalSprite1->setAnchorPoint(Vec2(0.5,0.5)); -// normalSprite1->setContentSize(Size(100,100)); + normalSprite1->setFlippedY(true); + this->addChild(normalSprite1); normalSprite1->runAction((FiniteTimeAction*)action->clone()); @@ -107,7 +108,8 @@ bool UIScale9SpriteHierarchialTest::init() auto moveBack = moveTo->reverse(); auto rotateBy = RotateBy::create(1.0f, 180); auto fadeOut = FadeOut::create(2.0f); - auto action = Sequence::create(moveTo,moveBack, rotateBy,fadeOut, NULL); + auto scaleTo = ScaleTo::create(1.0, 2.0); + auto action = Sequence::create(moveTo,moveBack, rotateBy,fadeOut,scaleTo, NULL); Sprite *normalSprite1 = Sprite::create("cocosui/animationbuttonnormal.png"); normalSprite1->setPosition(100, 270); @@ -135,6 +137,7 @@ bool UIScale9SpriteHierarchialTest::init() cocos2d::ui::Scale9Sprite *sp2 = ui::Scale9Sprite::create("cocosui/animationbuttonnormal.png"); sp2->setPreferredSize(sp1->getContentSize() * 1.2f); sp2->setColor(Color3B::GREEN); + sp2->setFlippedX(true); sp2->setContentSize(Size(100,100)); sp1->addChild(sp2); @@ -163,15 +166,13 @@ bool UIScale9SpriteTouchTest::init() auto containerForSprite1 = Node::create(); auto sprite1 = cocos2d::ui::Scale9Sprite::create("Images/CyanSquare.png"); -// sprite1->setScale9Enabled(false); sprite1->setPosition(origin+Vec2(size.width/2, size.height/2) + Vec2(-80, 80)); containerForSprite1->addChild(sprite1); addChild(containerForSprite1, 10); auto sprite2 = ui::Scale9Sprite::create("Images/MagentaSquare.png"); sprite2->setPosition(origin+Vec2(size.width/2, size.height/2)); -// sprite2->setCascadeOpacityEnabled(false); -// sprite2->setScale9Enabled(false); + addChild(sprite2, 20); @@ -179,7 +180,6 @@ bool UIScale9SpriteTouchTest::init() sprite3->setPosition(Vec2(0, 0)); sprite3->setCascadeOpacityEnabled(false); sprite2->addChild(sprite3, 1); -// sprite3->setScale9Enabled(false); // Make sprite1 touchable @@ -647,6 +647,9 @@ bool UIS9Flip::init() float x = winSize.width / 2; float y = 0 + (winSize.height / 2); + auto statusLabel = Label::createWithSystemFont("Scale9Enabled", "Arial", 10); + statusLabel->setPosition(Vec2(x, winSize.height - statusLabel->getContentSize().height - 40)); + this->addChild(statusLabel); auto normalSprite = ui::Scale9Sprite::createWithSpriteFrameName("blocks9r.png"); @@ -663,11 +666,11 @@ bool UIS9Flip::init() auto flipXSprite = ui::Scale9Sprite::createWithSpriteFrameName("blocks9r.png"); flipXSprite->setPosition(Vec2(x - 120, y )); + flipXSprite->setScale(1.2); this->addChild(flipXSprite); + flipXSprite->setFlippedX(false); - flipXSprite->setFlippedX(true); - - auto flipXLabel = Label::createWithSystemFont("Sprite FlipX","Airal",10); + auto flipXLabel = Label::createWithSystemFont("sprite is not flipped!","Airal",10); flipXLabel->setPosition(flipXSprite->getPosition() + Vec2(0, flipXSprite->getContentSize().height/2 + 10)); this->addChild(flipXLabel); @@ -677,12 +680,80 @@ bool UIS9Flip::init() flipYSprite->setPosition(Vec2(x + 120, y)); this->addChild(flipYSprite); + flipYSprite->setScale(0.8); flipYSprite->setFlippedY(true); - auto flipYLabel = Label::createWithSystemFont("Sprite FlipY","Airal",10); + auto flipYLabel = Label::createWithSystemFont("sprite is flipped!","Airal",10); flipYLabel->setPosition(flipYSprite->getPosition() + Vec2(0, flipYSprite->getContentSize().height/2 + 10)); this->addChild(flipYLabel); + + auto toggleFlipXButton = Button::create(); + toggleFlipXButton->setTitleText("Toggle FlipX"); + toggleFlipXButton->setPosition(flipXSprite->getPosition() + Vec2(0, - 20 - flipXSprite->getContentSize().height/2)); + toggleFlipXButton->addClickEventListener([=](Ref*){ + flipXSprite->setFlippedX(! flipXSprite->isFlippedX()); + if (flipXSprite->isFlippedX()) { + flipXLabel->setString("sprite is flipped!"); + } + else{ + flipXLabel->setString("sprite is not flipped!"); + } + }); + this->addChild(toggleFlipXButton); + + auto toggleFlipYButton = Button::create(); + toggleFlipYButton->setTitleText("Toggle FlipY"); + toggleFlipYButton->setPosition(flipYSprite->getPosition() + Vec2(0, -20 - flipYSprite->getContentSize().height/2)); + toggleFlipYButton->addClickEventListener([=](Ref*){ + flipYSprite->setFlippedY(!flipYSprite->isFlippedY()); + if (flipYSprite->isFlippedY()) { + flipYLabel->setString("sprite is flipped!"); + } + else{ + flipYLabel->setString("sprpite is not flipped!"); + } + }); + this->addChild(toggleFlipYButton); + + auto toggleScale9Button = Button::create(); + toggleScale9Button->setTitleText("Toggle Scale9"); + toggleScale9Button->setPosition(normalSprite->getPosition() + Vec2(0, -20 - normalSprite->getContentSize().height/2)); + toggleScale9Button->addClickEventListener([=](Ref*){ + flipXSprite->setScale9Enabled(!flipXSprite->isScale9Enabled()); + flipYSprite->setScale9Enabled(!flipYSprite->isScale9Enabled()); + if (flipXSprite->isScale9Enabled()) { + statusLabel->setString("Scale9Enabled"); + }else{ + statusLabel->setString("Scale9Disabled"); + } + + CCLOG("scaleX = %f", flipXSprite->getScaleX()); + CCLOG("scaleY = %f", flipYSprite->getScale()); + if (flipXSprite->isFlippedX()) { + CCLOG("xxxxxxx"); + } + if (flipYSprite->isFlippedY()) { + CCLOG("YYYYYY"); + } + + if (flipXSprite->isFlippedX()) { + flipXLabel->setString("sprite is flipped!"); + } + else{ + flipXLabel->setString("sprite is not flipped!"); + } + + if (flipYSprite->isFlippedY()) { + flipYLabel->setString("sprite is flipped!"); + } + else{ + flipYLabel->setString("sprpite is not flipped!"); + } + + }); + this->addChild(toggleScale9Button); + return true; } return false;