add geode::cocos::switchToScene utility

This commit is contained in:
HJfod 2022-10-23 17:54:42 +03:00
parent 5a8bc843dc
commit 17014b6302
3 changed files with 20 additions and 0 deletions
loader
include/Geode
src/utils

View file

@ -1,5 +1,8 @@
#pragma once
#include "../DefaultInclude.hpp"
#include <cocos2d.h>
namespace cocos2d {
class CCArray;
class CCNode;

View file

@ -123,6 +123,14 @@ namespace geode::cocos {
*/
GEODE_DLL cocos2d::CCRect calculateChildCoverage(cocos2d::CCNode* parent);
/**
* Create a CCScene from a layer and switch to it with the default fade
* transition
* @param layer Layer to create a scene from
* @returns Created scene (not the fade transition)
*/
GEODE_DLL cocos2d::CCScene* switchToScene(cocos2d::CCLayer* layer);
/**
* Rescale node to fit inside given size
* @param node Node to rescale

View file

@ -99,3 +99,12 @@ bool geode::cocos::fileExistsInSearchPaths(const char* filename) {
auto utils = CCFileUtils::sharedFileUtils();
return utils->isFileExist(utils->fullPathForFilename(filename, false));
}
CCScene* geode::cocos::switchToScene(CCLayer* layer) {
auto scene = CCScene::create();
scene->addChild(layer);
CCDirector::get()->replaceScene(CCTransitionFade::create(
.5f, scene
));
return scene;
}