MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / init

Method init

Source/LoadingLayer.cpp:146–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144}
145
146bool LoadingLayer::init() {
147 if (!Layer::init()) return false;
148
149 auto dir = Director::getInstance();
150
151 _sprFrameCache = SpriteFrameCache::getInstance();
152 _textureCache = dir->getTextureCache();
153
154 dir->setContentScaleFactor(GameManager::getInstance()->isHigh() ? 4.0f : 2.0f);
155
156 dir->purgeCachedData();
157 _sprFrameCache->removeSpriteFrames();
158 _textureCache->removeAllTextures();
159
160 size_t totalAssets = fonts.size() + plists.size() + pngs.size() + getPlayerIconsSize() + getShipIconsSize() + getPlayerBallIconsSize() + getBirdIconsSize();
161 this->m_nTotalAssets = static_cast<int>(totalAssets);
162
163 _textureCache->addImage(GameToolbox::getTextureString("GJ_LaunchSheet.png"));
164 _sprFrameCache->addSpriteFramesWithFile(GameToolbox::getTextureString("GJ_LaunchSheet.plist"));
165
166 auto winSize = dir->getWinSize();
167
168 auto bgSpr = Sprite::create(GameToolbox::getTextureString("game_bg_01_001.png"));
169 bgSpr->setStretchEnabled(false);
170 bgSpr->setPosition(winSize / 2);
171 bgSpr->setScale(winSize.width / bgSpr->getContentSize().width);
172 bgSpr->setColor({ 0, 102, 255 });
173 this->addChild(bgSpr);
174
175 auto logoSpr = Sprite::createWithSpriteFrameName("GJ_logo_001.png");
176 logoSpr->setStretchEnabled(false);
177 logoSpr->setPosition(winSize / 2);
178 this->addChild(logoSpr);
179
180 auto robLogoSpr = Sprite::createWithSpriteFrameName("RobTopLogoBig_001.png");
181 robLogoSpr->setStretchEnabled(false);
182 robLogoSpr->setPosition(logoSpr->getPosition() + Vec2(0, 80));
183 this->addChild(robLogoSpr);
184
185 auto splash = this->getSplash();
186 auto splashText = Label::createWithBMFont(GameToolbox::getTextureString("goldFont.fnt"), splash);
187 splashText->setPosition(winSize.width / 2, (winSize.height / 2) - 100);
188 splashText->setScale(0.7f);
189
190 this->addChild(splashText);
191 _pBar = SimpleProgressBar::create();
192 _pBar->setPercentage(0.f);
193 _pBar->setPosition({ winSize.width / 2, splashText->getPosition().height + 40 });
194 this->addChild(_pBar);
195
196 this->runAction(Sequence::create(DelayTime::create(0), CallFunc::create([this]() { this->loadAssets(); }), nullptr));
197
198#if SHOW_IMGUI == true
199 CocosExplorer::openForever();
200#endif
201
202
203 GameToolbox::log("quality medium: {}, scale factor {}", GameManager::getInstance()->isMedium(), dir->getContentScaleFactor());

Callers 1

createMethod · 0.45

Calls 11

getSplashMethod · 0.95
loadAssetsMethod · 0.95
createFunction · 0.85
logFunction · 0.85
isHighMethod · 0.80
sizeMethod · 0.80
setPositionMethod · 0.80
setScaleMethod · 0.80
isMediumMethod · 0.80
Vec2Class · 0.70
setColorMethod · 0.45

Tested by

no test coverage detected