Home > other >  Cocos2dx do game frames is very low, could you tell me why
Cocos2dx do game frames is very low, could you tell me why

Time:09-25

Recently in play a game, I met a very headache, is also very strange questions, specific description is as follows:

I had two versions of the code and version only 40 or so, a frame number and the version number of frames have 59 two, don't know why there are so much difference,

Version 1:

Auto mapLayer=Layer: : create ();//create a new map layer

Auto map=cMap: : create ();//create a new map

Vector
MapLayer - & gt; AddChild (map);//add a map to the map layer

for (int i=0; i<5040; I++)
{
Auto v=cMapUnit: : create ();//the new map unit

Auto mapUnitSprite=Sprite: : create (" mapUnit. PNG ");//create the elves

V - & gt; SetSprite (mapUnitSprite);

V - & gt; AddChild (mapUnitSprite);//add the elves to map unit

Vec. PushBack (v);//the map unit is added to the map unit vector

The map - & gt; AddChild (v);//the map unit is added to the map
}

The rendering efficiency is low, only about 40 frames,

Version 2:

Auto mapLayer=Layer: : create ();//create a new map layer

Auto map=cMap: : create ();//create a new map

Vector
MapLayer - & gt; AddChild (map);//add a map to the map layer

for (int i=0; i<5040; I++)
{
Auto v=cMapUnit: : create ();//the new map unit

Auto mapUnitSprite=Sprite: : create (" mapUnit. PNG ");//create the elves

V - & gt; SetSprite (mapUnitSprite);

MapLayer - & gt; AddChild (mapUnitSprite);//add the elves to map layer, this is the first difference between

Vec. PushBack (v);

//there is no map - & gt; AddChild (v); This is the second the difference, I found this sentence add after dramatically affects the efficiency of version a must have this sentence, otherwise will not render the map element
}

The rendering efficiency is high, the frames to 59,

I want to know why have so big difference, I want to use the version a, because of its structure better and easier to maintain,

Brother wood such as the great god, please guide, thank you!

CodePudding user response:

Without addChild wouldn't apply colours to a drawing, version 2 less than 5000 rendering unit, frame rate must be relatively fast

CodePudding user response:

Oh, I'm wrong...

CodePudding user response:

The first 5040 elves, much more than the second (speculation)
V - & gt; SetSprite (mapUnitSprite);//added 5040 elves

V - & gt; AddChild (mapUnitSprite);//added 5040 elves

CodePudding user response:

for (int i=0; i<5040; I++)
{
# cMapUnit create
Auto v=cMapUnit: : create ();//the new map unit
# # mapUnitSprite create
Auto mapUnitSprite=Sprite: : create (" mapUnit. PNG ");//create the elves
# cMapUnit operation
V - & gt; SetSprite (mapUnitSprite);
# # mapUnitSprite added to the node
MapLayer - & gt; AddChild (mapUnitSprite);//add the elves to map layer, this is the first difference between
# cMapUnit is not added to the node, although be vec for reference
Vec. PushBack (v);

}
  • Related