diff --git a/loader/include/Geode/ui/SceneManager.hpp b/loader/include/Geode/ui/SceneManager.hpp index 899562f4..b55df386 100644 --- a/loader/include/Geode/ui/SceneManager.hpp +++ b/loader/include/Geode/ui/SceneManager.hpp @@ -1,5 +1,8 @@ #pragma once +#include "../DefaultInclude.hpp" +#include <cocos2d.h> + namespace cocos2d { class CCArray; class CCNode; diff --git a/loader/include/Geode/utils/cocos.hpp b/loader/include/Geode/utils/cocos.hpp index cf7232de..7ed58a14 100644 --- a/loader/include/Geode/utils/cocos.hpp +++ b/loader/include/Geode/utils/cocos.hpp @@ -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 diff --git a/loader/src/utils/cocos.cpp b/loader/src/utils/cocos.cpp index 2751a052..8e3061ec 100644 --- a/loader/src/utils/cocos.cpp +++ b/loader/src/utils/cocos.cpp @@ -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; +}