Cocos2dx 2.1.4游戏,连续FPS下降且永不恢复 [英] Cocos2dx 2.1.4 Game, Continuos FPS drop and never recovers

查看:150
本文介绍了Cocos2dx 2.1.4游戏,连续FPS下降且永不恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用cocos2dx 2.1.4创建游戏.它的FPS持续下降,永不恢复. 请找到以下详细信息

I am creating a game using cocos2dx 2.1.4. Its FPS drops continuously , and never recover. Please find the details as follows

关于我做事方式的背景:- 它的游戏是向下滚动某些形状,每个形状都由一些正方形方块组成.我有7种方块.全部加载到Sprite Sheet中,并使用此Sprite Sheet中的这些块创建形状. 关卡文件由这些形状组成.我同时加载两个级别,一个在屏幕上,另一个在屏幕外,以使其无缝滚动.为了同时加载两个关卡,我使用了两个不同的CCSprite游戏批处理节点::-

Background about the way I am doing things:- Its game about scrolling down some shapes, each shape is made up of some square blocks.I have 7 kind of blocks. All loaded in a Sprite Sheet and using these blocks from this sprite sheet I create a shape. A level file is consist of these shapes. I load two levels at the same time one onscreen and another off screen to make it seamless scrolling. For loading two levels at the same time I used two different CCSprite game batch nodes as :-

  CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("56blackglow.plist");
_gameBatchNode1 = CCSpriteBatchNode::create("56blackglow.png", 200);
_gameBatchNode1->retain();
this->addChild(_gameBatchNode1,kForeground);

_gameBatchNode2= CCSpriteBatchNode::create("56blackglow.png", 200);
   _gameBatchNode2->retain();
    this->addChild(_gameBatchNode2,kForeground);

我面临的问题是,当我继续玩游戏时,帧速率从60 fps连续下降到10 fps,并且在我观察到20分钟后再也无法恢复或可能在不久的将来恢复,但是我花了太多时间等待.

The problem I am facing is that as I keep on playing the game frame rate drops continuously , from 60 fps till 10 fps and never recovers or might recover in near future , as I observed for 20 minutes but its too much time to wait.

我的观察:-

1>我使用了时间分析器,它显示最大时间在draw()调用中.同样,如果我玩得非常快,时间的高峰会随着赛道的增加而增加,这应该很好,因为我需要做更多的工作,但是一旦达到高峰,即使我离开游戏空闲,它也只会保持在那个高度.正常吗?根据我的说法,一旦完成当前工作,它应该已经恢复到正常的峰值.

1> I used Time profiler it shows maximum time is in draw() calls. Also if I play game very fast the peak of time increases in track, that should be fine as I am giving more work to do, but once a peak is attained it remains approximately at that height only, even if I leave the game Idle. Is it normal ? According to me it should have returned to its normal peak once the current work is done.

2>在某些我认为发生这种情况的地方,因为我使用了两个批处理节点,并且在用户触摸时立即删除其子级可能会使其变慢,但是在删除了子级之后,它应该可以正常运行.给一个想法可以立即从批处理节点中删除10个子级吗?有人说它的过程很慢.只是为了检查这是否引起问题,我做了:-

2> Some where I thought its happening because I used two batch nodes and removing its children on a user touch immediately might causing it slow but then after removing the children it should run normal. to give an idea is it ok to remove 10 children from batch node immediately ? some guys say its very slow process. Just to check if this causing problem , I did :-

我并没有删除它们,而是将孩子的可见性设置为false.但是FPS仍然下降并且永远无法恢复.

Instead of removing them I just set visibility of the children to false.But still FPS drops and never recovers.

请分享您对此的想法.

推荐答案

刚刚发现,每次触摸时,我都会向该图层添加8个新的sprite,并且每次触摸时都会添加它.因此,随着时间的流逝,我将付出越来越多的工作.这是问题

Just found that with every touch, I am adding 8 new sprites to the layer, and its adding every time I touch . So with time I am giving more and more work to do. This is the problem

实际上,我想通过触摸来替换8个地方的精灵,就像我每次都做的那样:-

Actually I wanted to replace the sprite at 8 places with a touch, the way I was doing every time :-

_colorBottom1=CCSprite::createWithSpriteFrameName(png[0]);
    this->addChild(_colorBottom1,kForeground);
    _colorBottom1->setPosition(ccp((_colorPanelLeftPad)*_blockWidth,_blockWidth));

这导致每次触摸时都会添加此精灵.

It was causing this sprite to be added with every touch.

,但是它应该是(替换纹理而不是再次创建Sprite):-

but it should have been (Replace the texture instead of creating the Sprite again):-

CCSpriteFrame *frame1=CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(png0);
_colorBottom1->setDisplayFrame(frame1);

这篇关于Cocos2dx 2.1.4游戏,连续FPS下降且永不恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆