cocos2d :: extension :: ScrollView :: create()导致未解析的外部符号(VS2012)

时间:2014-08-25 21:23:27

标签: cocos2d-x cocos2d-x-3.0

我在使用cocos2d-x向菜单添加滚动视图时遇到了困难。我使用cocos2d :: extension :: ScrollView :: create()来创建滚动,但是在编译时,我收到错误:

错误6错误LNK2019:未解析的外部符号" public:static class cocos2d :: extension :: ScrollView * __cdecl cocos2d :: extension :: ScrollView :: create(class cocos2d :: Size,class cocos2d :: Node *)" (?创建@ ScrollView @ extension @ cocos2d @@ SAPAV123 @ VSize @ 3 @ PAVNode @ 3 @@ Z)在函数&#34中公开:public:virtual bool __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();
}

1 个答案:

答案 0 :(得分:0)

问题确实与@VikasPatidar建议的内容有关。将libExtensions项目添加到我的解决方案中解决了部分问题。

出现的下一个问题是包含文件Mutex和Thread的一系列缺失引用。这些文件是C ++的一部分,包含在VS2012中。问题是它们不是libExtensions项目中外部依赖项的一部分,也无法弄清楚如何添加它们。

为解决这个问题,我在游戏的文件夹/ cocos2d / build下打开了cocos2d-win32.vc2012.sln。当我这样做时,VS发现它不同步并要求我同步。同步后,所有外部依赖项都已正确映射。请注意,我在我的游戏文件夹中执行了此操作,而不是Cocos / cocos2d-x-3.0文件夹。

我个人认为这是因为我从cocos获得的原始下载与vs2012不兼容,而是与vs2010兼容,因为libExtensions项目正在加载vs2010标记。

总结一下,

  1. 添加cocos2d / extensions / proj.win32 / libExtensions.vcxproj项目 现有的解决方案。
  2. 确保它与VS2012兼容。要同步它,只需打开游戏中的build / cocos2d-win32.vc2012.sln,然后按照提示进行同步。
  3. 请注意,这是VS特有的。 Eclipse和Android可能是另一个问题。

相关问题