MCPcopy Create free account
hub / github.com/axmolengine/axmol / createStatsLabel

Method createStatsLabel

core/base/Director.cpp:1338–1400  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1336}
1337
1338void Director::createStatsLabel()
1339{
1340 Texture2D* texture = nullptr;
1341 std::string fpsString = "00.0";
1342 std::string drawBatchString = "000";
1343 std::string drawVerticesString = "00000";
1344 if (_FPSLabel)
1345 {
1346 fpsString = _FPSLabel->getString();
1347 drawBatchString = _drawnBatchesLabel->getString();
1348 drawVerticesString = _drawnVerticesLabel->getString();
1349
1350 AX_SAFE_RELEASE_NULL(_FPSLabel);
1351 AX_SAFE_RELEASE_NULL(_drawnBatchesLabel);
1352 AX_SAFE_RELEASE_NULL(_drawnVerticesLabel);
1353 _textureCache->removeTextureForKey("/ax_fps_images");
1354 FileUtils::getInstance()->purgeCachedEntries();
1355 }
1356
1357 unsigned char* data = nullptr;
1358 ssize_t dataLength = 0;
1359 getFPSImageData(&data, &dataLength);
1360
1361 Image* image = new Image();
1362 bool isOK = image->initWithImageData(data, dataLength, false);
1363 if (!isOK)
1364 {
1365 if (image)
1366 delete image;
1367 AXLOGE("{}", "Fails: init fps_images");
1368 return;
1369 }
1370
1371 texture = _textureCache->addImage(image, "/ax_fps_images", PixelFormat::RGBA4);
1372 AX_SAFE_RELEASE(image);
1373
1374 /*
1375 We want to use an image which is stored in the file named ccFPSImage.c
1376 for any design resolutions and all resource resolutions.
1377
1378 To achieve this, we need to ignore 'contentScaleFactor' in 'AtlasNode' and 'LabelAtlas'.
1379 So I added a new method called 'setIgnoreContentScaleFactor' for 'AtlasNode',
1380 this is not exposed to game developers, it's only used for displaying FPS now.
1381 */
1382 float scaleFactor = 1 / AX_CONTENT_SCALE_FACTOR();
1383
1384 _FPSLabel = LabelAtlas::create(fpsString, texture, 12, 32, '.');
1385 _FPSLabel->retain();
1386 _FPSLabel->setIgnoreContentScaleFactor(true);
1387 _FPSLabel->setScale(scaleFactor);
1388
1389 _drawnBatchesLabel = LabelAtlas::create(drawBatchString, texture, 12, 32, '.');
1390 _drawnBatchesLabel->retain();
1391 _drawnBatchesLabel->setIgnoreContentScaleFactor(true);
1392 _drawnBatchesLabel->setScale(scaleFactor);
1393
1394 _drawnVerticesLabel = LabelAtlas::create(drawVerticesString, texture, 12, 32, '.');
1395 _drawnVerticesLabel->retain();

Callers

nothing calls this directly

Calls 10

getInstanceFunction · 0.85
createFunction · 0.85
removeTextureForKeyMethod · 0.80
purgeCachedEntriesMethod · 0.80
getStringMethod · 0.45
initWithImageDataMethod · 0.45
addImageMethod · 0.45
retainMethod · 0.45
setScaleMethod · 0.45

Tested by

no test coverage detected