我收到了以下错误,但我的代码应该没有问题。因为我已经声明了createScene方法。如果有一些提示或提示可以解决这个问题,那就太好了!
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap/dist/css/bootstrap-theme.min.css' // optional
import 'jquery/dist/jquery.min.js'
import 'bootstrap/dist/js/bootstrap.min.js'
AppDelegate.cpp:82:这是发生错误的地方
AppDelegate.cpp:82: error: undefined reference to 'MainScene::createScene()'
collect2: error: ld returned 1 exit status
这是MainScene.cpp
// create a scene. it's an autorelease object
auto scene = MainScene::createScene();
这是MainScene.h
#include "MainScene.h"
USING_NS_CC; //Means using cocos2d
MainScene::MainScene() {
}
MainScene::~MainScene() {
}
Scene* MainScene::createScene() {
auto scene = Scene::create();
auto layer = MainScene::create();
scene->addChild(layer);
return scene;
}
bool init() {
if (!Layer::init()) {
return false;
}
auto director = Director::getInstance();
auto size = director->getWinSize();
auto background = Sprite::create("background.png");
background->setPosition(Vec2(size.width/2.0, size.height / 2.0));
this->addChild(background);
//initialize process
return true;
}
答案 0 :(得分:1)
我认为您忘记定义init()
类
MainScene
方法
bool init() {
...
...
}
将其更改为
bool MainScene::init(){
...
...
}
答案 1 :(得分:0)
Scene* MainScene::createScene() {
应为cocos2d::Scene* MainScene::createScene() {
定义需要匹配实现。