1、骨骼动画绑定上去的 CCNode 没有被释放,有内存泄露!比如我战斗中 伤害显示、卡牌战斗动作等都是用 骨骼动画 的。 一场战斗下来内存泄露的厉害。屏蔽绑定语句,世界就清净了!!
2、骨骼动画没做多分辨率支持! 不同分辨率需要单独提供,求提供比较完善的解决方案。(不要提供类似 使用更大分辨率下的骨骼动画来代替这样的方法!)
我用的版本是 cocos2dx2.2.3
1、骨骼动画绑定上去的 CCNode 没有被释放,有内存泄露!比如我战斗中 伤害显示、卡牌战斗动作等都是用 骨骼动画 的。 一场战斗下来内存泄露的厉害。屏蔽绑定语句,世界就清净了!!
2、骨骼动画没做多分辨率支持! 不同分辨率需要单独提供,求提供比较完善的解决方案。(不要提供类似 使用更大分辨率下的骨骼动画来代替这样的方法!)
我用的版本是 cocos2dx2.2.3
下面是在HelloCpp中 增加 更换bonde内容的测试代码, 内存一直在增加。 附件为测试工程
#include “HelloWorldScene.h”
#include “AppMacros.h”
#include “cocos-ext.h”
USING_NS_CC;
using namespace cocos2d::extension;
CCScene* HelloWorld::scene()
{
// ‘scene’ is an autorelease object
CCScene *scene = CCScene::create();
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on “init” you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// add a "close" icon to exit the progress. it's an autorelease object
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback));
pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
origin.y + pCloseItem->getContentSize().height/2));
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);
/////////////////////////////
// 3. add your codes below...
// add a label shows "Hello World"
// create and initialize a label
CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", TITLE_FONT_SIZE);
// position the label on the center of the screen
pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - pLabel->getContentSize().height));
// add the label as a child to this layer
this->addChild(pLabel, 1);
// add "HelloWorld" splash screen"
CCSprite* pSprite = CCSprite::create("HelloWorld.png");
// position the sprite on the center of the screen
pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
this->addChild(pSprite, 0);
//增加测试代码
m_preTime = GetTickCount();
CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo( "_mcjiaxue_jianxue/_mcjiaxue_jianxue.ExportJson" );
m_pArmature = CCArmature::create("_mcjiaxue_jianxue");
m_pArmature->getAnimation()->playWithIndex(0);
addChild(m_pArmature);
m_pArmature->setPosition(ccp(origin.x + (visibleSize.width - m_pArmature->getContentSize().width )/2,
origin.y + (visibleSize.height - m_pArmature->getContentSize().height)/2 ));
scheduleUpdate();
schedule( schedule_selector(HelloWorld::OnSchedule) );
return true;
}
void HelloWorld::OnSchedule(float)
{
//增加测试代码, 1秒播放一次同一个动画
unsigned long now = GetTickCount();
if( m_preTime + 200 <= now )
{
ShowNumberArmature();
m_preTime=now;
}
}
void HelloWorld::ShowNumberArmature()
{
static int s_index = 0;
CCSprite *pSp;
if( (++s_index)%2 ==0)
pSp = CCSprite::create("_bj1.png");
else
pSp = CCSprite::create("_bj2.png");
CCBone* bone = m_pArmature->getBone("Layer1");
bone->removeDisplay(0);
bone->addDisplay(pSp, 0);
bone->changeDisplayWithIndex(0, true);
bone->setIgnoreMovementBoneData(true);
}
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
CCMessageBox(“You pressed the close button. Windows Store Apps do not implement a close button.”,“Alert”);
#else
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
#endif
}
我在用bone->removeDisplay的时候老是出问题,虽然把这个渲染资源释放了,但还是回去更新,执行这段代码:
DecorativeDisplay *decoDisplay = bone->getDisplayManager()->getCurrentDecorativeDisplay();
ColliderDetector *detector = decoDisplay->getColliderDetector();
然后就报错找不到decoDisplay 。。。求解释
今天突然看到自己一个月前的帖子,完了结贴了…
2个问题都已搞定…
内存泄露是由于使用了 CCBlink ,这个类应该有问题。 所有放弃使用了。
多分辨率的问题,看源代码,稍作修改即可。
、骨骼动画绑定上去的 CCNode 没有被释放,有内存泄露! 能具体说下么?我也有这个问题。