我在使用cocos2d-x向菜单中添加滚动视图时遇到了困难。我使用cocos2d::扩展名::ScrollView::create ()来创建滚动,但是在编译时,我得到了错误:
错误6错误LNK2019:未解决的外部符号"public:静态类cocos2d::__cdecl::create“(类cocos2d::Size,类cocos2d::Node *)“函数中引用的(?create@ScrollView@extension@cocos2d@@SAPAV123@VSize@3@PAVNode@3@@Z) "public: virtual __thiscall ScrollMenuScene::init(void)”(?init@ScrollMenuScene@@UAE_NXZ) C:\Cocos\cocos2d-x-3.0~\MyCompany\MyGame\proj.win32\ScrollMenuScene.obj MyGame
下面是h和cpp文件的代码片段,一直到熊最小值,但包括导致生成错误的所有必要代码。
导致错误的主线是:
_scrollView = cocos2d::extension::ScrollView::create(_scrollContainer->getContentSize(), _scrollContainer);如果我不实例化_scrollView指针,它就不会出错,所以当我调用ScrollView::create时,它就特别发生了。
任何帮助都将不胜感激。谢谢。
*注意,在下面的代码中,我添加了整个文件,以显示包含、定义和实现,因为这通常是我发现未解决错误的地方。
.h文件
#ifndef SCROLL_MENU_SCENE_H
#define SCROLL_MENU_SCENE_H
#include "cocos2d.h"
#include "cocos-ext.h"
class ScrollMenuScene : public cocos2d::Layer
{
private:
cocos2d::Node* _scrollContainer;
cocos2d::extension::ScrollView *_scrollView;
cocos2d::Menu* _menu;
public:
// there's no 'id' in cpp, so we recommend returning the class instance pointer
static cocos2d::Scene* createScene();
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
~ScrollMenuScene(void);
// implement the "static create()" method manually
CREATE_FUNC(ScrollMenuScene);
//Menu callback.
void Menu_Handler(cocos2d::Ref* sender);
};
#endif //SCROLL_MENU_SCENE_H.cpp文件
#include "ScrollMenuScene.h"
cocos2d::Scene* ScrollMenuScene::createScene()
{
// 'scene' is an autorelease object
auto scene = cocos2d::Scene::create();
// 'layer' is an autorelease object
auto layer = ScrollMenuScene::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool ScrollMenuScene::init()
{
//Call base first.
if (!Layer::init())
{
return false;
}
cocos2d::Point worldCenter = cocos2d::Point(this->getContentSize() / 2);
_scrollContainer = cocos2d::Node::create();
_scrollContainer->setPosition(worldCenter);
_scrollContainer->setContentSize(this->getContentSize() / 2); //half the size of the layer.
_scrollView = cocos2d::extension::ScrollView::create(_scrollContainer->getContentSize(), _scrollContainer);
_scrollView->setPosition(worldCenter);
_scrollView->setDirection(cocos2d::extension::ScrollView::Direction::VERTICAL);
//Add Menu.
cocos2d::MenuItemImage *item0 = cocos2d::MenuItemImage::create("Images/PlayMenu/PlayMenuTile0.png",
"Images/PlayMenu/PlayMenuTile0.png", this, menu_selector(ScrollMenuScene::Menu_Handler));
_menu = cocos2d::Menu::create();
_menu->addChild(item0);
_menu->alignItemsVerticallyWithPadding(20);
_menu->setPosition(worldCenter);
this->addChild(_menu);
//add scroll view to layer.
this->addChild(_scrollView);
return true;
}
void ScrollMenuScene::Menu_Handler(cocos2d::Ref* sender)
{
//<Menu item tap implementation>
}
ScrollMenuScene::~ScrollMenuScene()
{
_scrollContainer->release();
}发布于 2014-08-29 00:09:12
这个问题确实与@VikasPatidar的建议有关。将libExtensions项目添加到我的解决方案中可以解决部分问题。
出现的下一个问题是缺少了一系列包含文件Mutex和Thread的引用。这些文件是C++的一部分,并包含在VS2012中。问题是,它们不是libExtensions项目中外部依赖项的一部分,并且无法确定如何添加它们。
为了解决这个问题,我在我的游戏文件夹/cocos2d/build下打开了cocos2d-win32.vc2012.sln。当我这样做时,VS发现它不同步,并要求我同步。同步之后,所有外部依赖项都被正确映射。请注意,我是在我的游戏文件夹中这样做的,而不是Cocos/cocos2d-x-3.0文件夹。
我个人认为这是因为我从cocos获得的原始下载与vs2012不兼容,但vs2010却是因为libExtensions项目加载了vs2010标志。
总之,
注意,这是VS特有的。Eclipse和Android在一起可能是另一个问题。
https://stackoverflow.com/questions/25494588
复制相似问题