Error on "mainMenu::createScene()"

I am using a script called “MainMenuScene.cpp” and the game is supposed to switch to the scene from “IntroScene.cpp.” I am using

auto menu = MainMenu::createScene();
Director::getInstance()->replaceScene(TransitionFade::create(15, menu, Color3B(0,0,0)));

but it is giving an error that I don’t really understand, it says “Undefined Symbol: mainMenu::createScene();”
I do not understand how this is here, because in “MainMenuScene.h,” it is creating MainMenuScene.cpp

It means that signature is not found.

Show us your header and source

what do you mean header and source

your .h and your .cpp

IntroScene.cpp:

#include "IntroScene.h"
#include <AudioEngine.h>
#include "MainMenuScene.h"

USING_NS_CC;

Scene* Intro::createScene()
{
    return Intro::create();
}

static void problemLoading(const char* filename)
{
    printf("Error while loading: %s\n", filename);
    printf("Depending on how you compiled you might have to add 'Resources/' in front of filenames in IntroScene.cpp\n");
}

bool Intro::init()
{
    if ( !Scene::init() )
    {
        return false;
    }
    
    auto visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    // Create "mainMenu" scene
    
    // Initialize spritesheets
    auto spritecache = SpriteFrameCache::getInstance();
    spritecache->addSpriteFramesWithFile("GameSheet03-uhd.plist");
    spritecache->addSpriteFramesWithFile("LaunchSheet-uhd.plist");
    
    // Intro - Title
    auto logo_title = Sprite::createWithSpriteFrameName("logo_001.png");
    auto logo_title_rescale = ScaleTo::create(1, 0.4f,0.4f);
    auto logo_title_move = MoveTo::create(1, Vec2(visibleSize.width / 2,visibleSize.height / 2));
    auto logo_title_intro_rescale_ease = EaseIn::create(logo_title_rescale->clone(),2);
    auto logo_title_intro_move_ease = EaseIn::create(logo_title_move->clone(), 2);
    auto logo_title_intro_anim = Spawn::createWithTwoActions(logo_title_intro_rescale_ease,logo_title_intro_move_ease);
    auto delay = DelayTime::create(4);
    auto logo_title_sequence = Sequence::create(logo_title_intro_anim,nullptr);
    logo_title->setPosition(Vec2(visibleSize.width / 2,visibleSize.height * -1));
    this->addChild(logo_title,0);
    
    // Intro - Text
    auto intro_text = Label::createWithBMFont("bigFont-uhd.fnt","Fanmade 2.2");
    intro_text->setPosition(Vec2(visibleSize.width / 2,visibleSize.height * -1));
    intro_text->setColor(Color3B(26,158,3));
    auto intro_text_move = MoveTo::create(0.3f,Vec2(visibleSize.width / 2, visibleSize.height / 2.5f));
    auto intro_transition = CallFunc::create([]() {
        // Main menu
        auto mainMenu = Scene::create();
        Director::getInstance()->replaceScene(TransitionFade::create(15, mainMenu, Color3B(0,0,0)));
        LayerColor *_bgColor = LayerColor::create(Color4B(53,23,200,255));
        mainMenu->addChild(_bgColor,-10);
        auto load = Label::createWithBMFont("bigFont-uhd.fnt","Loading Game...");
        auto visibleSize = Director::getInstance()->getVisibleSize();
        load->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
        load->setScale(0.2f,0.2f);
        mainMenu->addChild(load);
        auto delay = DelayTime::create(18);
        auto mainmenu_finished_loading = CallFunc::create([]() {
            // Main menu
            auto menu = MainMenu::createScene();
            Director::getInstance()->replaceScene(TransitionFade::create(15, menu, Color3B(0,0,0)));
            /*
             // this is the stuff I moved to MainMenuScene.cpp
            auto mainMenu = Scene::create();
            Director::getInstance()->replaceScene(TransitionFade::create(15, mainMenu, Color3B(0,0,0)));
            LayerColor *_bgColor = LayerColor::create(Color4B(53,23,200,255));
            mainMenu->addChild(_bgColor,-10);
            auto ach = Label::createWithBMFont("bigFont-uhd.fnt","Fanmade!");
            auto visibleSize = Director::getInstance()->getVisibleSize();
            ach->setPosition(Vec2(visibleSize.width / 2, visibleSize.height * 1.05f));
            auto ach_move = MoveTo::create(1,Vec2(visibleSize.width / 2, visibleSize.height / 1.1f));
            auto ach_move_ease = EaseOut::create(ach_move->clone(), 0.5f);
            ach->setScale(0.2f,0.2f);
            auto poweredby = Label::createWithBMFont("Font05-uhd.fnt","Powered By");
            auto cocos2dxlogo = Sprite::createWithSpriteFrameName("cocos2DxLogo.png");
            cocos2dxlogo->setPosition(Vec2(visibleSize.width * 0.17f, visibleSize.height * 0.03f));
            poweredby->setPosition(Vec2(visibleSize.width * 0.052f, visibleSize.height * 0.03f));
            cocos2dxlogo->setScale(0.25f,0.25f);
            poweredby->setScale(0.15f,0.15f);
            mainMenu->addChild(ach);
            mainMenu->addChild(cocos2dxlogo);
            mainMenu->addChild(poweredby);
            auto userdefaults = cocos2d::UserDefault::getInstance();
            Director::getInstance()->replaceScene(mainMenu);
            if(!userdefaults->getBoolForKey("notNew")){
                AudioEngine::play2d("achievement_01.mp3", false, 1.0f, nullptr);
                ach->runAction(ach_move_ease);
            }
            userdefaults->setBoolForKey("notNew", true);
            //sprintf(userdefaults->getIntegerForKey("newUser"));
            AudioEngine::play2d("menuLoop.mp3", true, 1.0f, nullptr);
             */
        });
        auto helperSprite = Sprite::create("tutorial_05.png");
        helperSprite->setScale(0, 0);
        auto helperSpriteSequence = Sequence::create(delay,mainmenu_finished_loading,nullptr);
        mainMenu->addChild(helperSprite);
        helperSprite->runAction(helperSpriteSequence);
    });
    auto intro_text_sequence = Sequence::create(intro_text_move,delay->clone(),intro_transition,nullptr);
    intro_text->setScale(0.25f,0.25f);
    this->addChild(intro_text);
    
    // Animate intro
    logo_title->runAction(logo_title_sequence);
    intro_text->runAction(intro_text_sequence);
    
    return true;
}


void Intro::menuCloseCallback(Ref* pSender)
{
    Director::getInstance()->end();
}

IntroScene.h:

#ifndef __INTRO_SCENE_H__
#define __INTRO_SCENE_H__

#include "cocos2d.h"

class Intro : public cocos2d::Scene
{
public:
    static cocos2d::Scene* createScene();

    virtual bool init();
    
    // a selector callback
    void menuCloseCallback(cocos2d::Ref* pSender);
    
    // implement the "static create()" method manually
    CREATE_FUNC(Intro);
};

#endif // __HELLOWORLD_SCENE_H__

MainMenuScene.cpp:

#include "MainMenuScene.h"
#include <AudioEngine.h>

USING_NS_CC;

Scene* MainMenu::createScene()
{
    return MainMenu::create();
}

static void problemLoading(const char* filename)
{
    printf("Error while loading: %s\n", filename);
    printf("Depending on how you compiled you might have to add 'Resources/' in front of filenames in IntroScene.cpp\n");
}

bool MainMenu::init()
{
    if ( !Scene::init() )
    {
        return false;
    }
    
    auto visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    // Create "mainMenu" scene
    
    // Initialize spritesheets
    auto spritecache = SpriteFrameCache::getInstance();
    spritecache->addSpriteFramesWithFile("GameSheet03-uhd.plist");
    spritecache->addSpriteFramesWithFile("LaunchSheet-uhd.plist");
    
    auto testSprite = Sprite::createWithSpriteFrameName("playBtn.png");
    this->addChild(testSprite);
    
    return true;
}


void MainMenu::menuCloseCallback(Ref* pSender)
{
    Director::getInstance()->end();
}

MainMenuScene.h:

#ifndef __MAINMENU_SCENE_H__
#define __MAINMENU_SCENE_H__

#include "cocos2d.h"

class MainMenu : public cocos2d::Scene
{
public:
    static cocos2d::Scene* createScene();

    virtual bool init();
    
    // a selector callback
    void menuCloseCallback(cocos2d::Ref* pSender);
    
    // implement the "static create()" method manually
    CREATE_FUNC(MainMenu);
};

#endif // __HELLOWORLD_SCENE_H__

Have you added your source file MainMenuScene.cpp to CMakeLists.txt?

2 Likes

Thank you! I did not know that I had to add the scene scripts to CMakeLists.txt

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.