引擎cocos2d-x-3.1.1

一、 cocos创建一个项目。随便是lua还是cpp。这里用cpp演示

二、创建完毕之后执行下项目

之后创建两个类。例如以下

TestLib.cpp文件

#include "TestLib.h"
#include "People.h" Scene* TestLib::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::create(); // 'layer' is an autorelease object
auto layer = TestLib::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 TestLib::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
} Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin(); /////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it. // add a "close" icon to exit the progress. it's an autorelease object
auto closeItem = MenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
CC_CALLBACK_1(TestLib::menuCloseCallback, this)); closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
origin.y + closeItem->getContentSize().height/2)); // create menu, it's an autorelease object
auto menu = Menu::create(closeItem, NULL);
menu->setPosition(Vec2::ZERO);
this->addChild(menu, 1); /////////////////////////////
// 3. add your codes below... // add a label shows "Hello World"
// create and initialize a label lab_ = LabelTTF::create("Hello World", "Arial", 24); // position the label on the center of the screen
lab_->setPosition(Vec2(origin.x + visibleSize.width / 2,
origin.y + visibleSize.height - lab_->getContentSize().height)); // add the label as a child to this layer
this->addChild(lab_, 1); // add "HelloWorld" splash screen"
auto sprite = Sprite::create("HelloWorld.png"); // position the sprite on the center of the screen
sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer
this->addChild(sprite, 0); return true;
} void TestLib::menuCloseCallback(Ref* pSender)
{
/*
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
return;
#endif Director::getInstance()->end(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
*/
lab_->setString("using test lib"); People* sp = People::create();
sp->setPosition(ccp(200, 300));
this->addChild(sp);
}

TestLib.h文件

#ifndef __TestLib_H__
#define __TestLib_H__ #include "cocos2d.h"
USING_NS_CC; class TestLib : public cocos2d::Layer
{
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(); // a selector callback
void menuCloseCallback(cocos2d::Ref* pSender); // implement the "static create()" method manually
CREATE_FUNC(TestLib); LabelTTF* lab_;
}; #endif // __HELLOWORLD_SCENE_H__

people.cpp文件

#include "People.h"

People::People()
{ }
People::~People()
{ }
bool People::init()
{
if (!Node::init())
{
return false;
} Sprite* sp = Sprite::create("CloseNormal.png");
addChild(sp); return true;
}

people.h文件

#ifndef __People_H__
#define __People_H__ #include "cocos2d.h"
USING_NS_CC; class People : public cocos2d::Node
{
public:
People();
~People();
virtual bool init(); CREATE_FUNC(People);
}; #endif // __HELLOWORLD_SCENE_H__

三、 两个试验类已经创建完毕。这个时候执行下程序。

而且改动AppDelegate,原先是引到helloworld,改成引到testlib。程序执行通过就成,是为了保证试验类没有错误。

四、改动project配置。

1 打开project属性

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGF5ZGF5dXBfY2hm/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

2 找到配置属性-》常规-》配置类型    改成静态库

3  选择完毕后点-》应用-》确定。之后就是生成lib

4 生成的文件在  testCpp\proj.win32\Debug.win32该文件夹下

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGF5ZGF5dXBfY2hm/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

5 新建还有一个cppproject,这两个加上testlib.h和people.h。一共四个文件拷贝到新project的class文件夹下

使用lib库有两个方法,一个是直接把lib引到project文件夹下,在须要用到的地方include一下就能够。

代码是:#pragma comment(lib, "testCpp.lib")

另外一个方法是直接设置库路径,就不用把lib引到project文件夹下了。直接点开project属性,在配置属性-》连接器-》常规-》附加库文件夹中加入库

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGF5ZGF5dXBfY2hm/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

之后确认。

在配置属性-》连接器-》输入-》附加依赖项。如图填写

之后确定。执行project就能够了

说明   .obj的文件不须要像lib一样。

直接加入到project文件夹下直接用就能够

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGF5ZGF5dXBfY2hm/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

vs2013生成lib的更多相关文章

  1. VS2013生成、使用dll,lib文件

    VS2013生成DLL文件 vs2013创建及使用DLL 一般来说项目偏爱生成dll动态库文件,因为可以解决静态库造成的空间浪费和更新困难问题,另外创建静态库时,我一般是建立空项目后,在项目配置类型中 ...

  2. VS2008 工程只生成dll不生成lib的解决方案

    http://topic.csdn.net/u/20081216/22/b12d1450-7585-4c9f-867a-7c181737c328.html 问题:vs2008版本的,不知道为什么只生成 ...

  3. VC生成lib的_stdcall函数名与mingw生成的不一致

    Qt Creator在Windows系统中,怎样链接VC生成的动态链接库 这个问题曾经困扰了我一整天.我想的是按照VC中的方法,增加include文件,增加lib文件,然后编译即可.谁知链接时总是出现 ...

  4. 由动态库文件dll生成lib库文件(手动生成.def文件,然后使用lib命令编译,非常牛),同理可使用dll生成.a库文件

    本文基于OpenBlas的编译和安装,来说明如何从一个dll文件生成lib库文件. 参考OpenBlas的说明“Howto generate import library for MingW”,和Mi ...

  5. Keil MDK中单个c文件生成LIB文件

    看大多数说的都是简单地将整个工程转换成.LIB,在Project->Options for Target->Output下,选择Create Library,就可以了. 不过这样生成的li ...

  6. (转)sqlite3生成lib遇到的问题

    今天想用一用sqlite,但是下载后发现只有DLL,没有LIB,只能自己生成了.在H:/Program Files/Microsoft Visual Studio 8/VC/bin里面有个lib.ex ...

  7. C++ VS编译问题--VS下生成DLL,但没有生成Lib的解决办法

    如果项目生成了.dll文件,但是没有生成.lib文件,这是由于项目的设置错误,应作如下修改: 项目->属性->链接器->输入->模块定义文件,设置你的模块定义文件,默认为lib ...

  8. 由.def文件生成lib文件[转]

    最近在学习curl库时,碰到一个问题,从官网上下载了一个lib版的,却发现只有.dll,没有lib文件,感觉很奇怪,google了之后才知道,原来库作者的用意是让用户自己生成lib文件,下载到的lib ...

  9. 由动态库文件dll生成lib库文件

    本文基于OpenBlas的编译和安装.来说明怎样从一个dll文件生成lib库文件. 參考OpenBlas的说明"Howto generate import library for MingW ...

随机推荐

  1. swift -Dynamic Dispatch

    These instructions perform dynamic lookup of class and generic methods. The class_method and super_m ...

  2. 【原创】webbluetoorh 在windows下无法显示搜索列表,在mac下正常的解决办法

    google webbluetooth在windows下不能弹出设备搜索列表提示“Web Bluetooth API is not available”,因为webbluetooth是google新推 ...

  3. 【转】自动识别是手机端还是pc端只用一行代码就搞定

    <script type="text/javascript"> var mobileAgent = new Array("iphone", &quo ...

  4. date - 打印或设置系统日期和时间

    总览 date [选项]... [+格式] date [选项] [MMDDhhmm[[CC]YY][.ss]] 描述 根据指定格式显示当前时间或设置系统时间. -d, --date=STRING 显示 ...

  5. freenas 系统可能存在的bug

    1.portal 中ip端口显示有问题. 2.创建extend/target映射之后重启iscsi服务有的时候不能启动. 3.后台/usr /etc 重启系统会自动还原.

  6. Redux的中间件Middleware不难,我信了^_^

    Redux的action和reducer已经足够复杂了,现在还需要理解Redux的中间件.为什么Redux的存在有何意义?为什么Redux的中间件有这么多层的函数返回?Redux的中间件究竟是如何工作 ...

  7. Java设计模式之策略模式(Strategy Pattern)

    简介 策略模式定义了算法族,分别封装起来,让它们之间可以互相替换,此模式让算法的变化独立于使用算法的客户. 组成 1.抽象策略角色(Strategy): 策略类,通常由一个接口或者抽象类实现. 2.具 ...

  8. redis(以php代码为例)

    备注:redis及phpredis扩展安装请查看:PHP典型功能与Laravel5框架开发学习笔记 redis具有原子性,所以在高并发情况下确保数据的一致性 一.连接 $redis = new Red ...

  9. 【转】C语言中access函数

    头文件:unistd.h 功 能: 确定文件或文件夹的访问权限.即,检查某个文件的存取方式,比如说是只读方式.只写方式等.如果指定的存取方式有效,则函数返回0,否则函数返回-1. 用 法: int a ...

  10. 用python爬取一张仓鼠图片

    一. 找到一张仓鼠图片并复制一下它的url url='http://img.go007.com/2017/08/16/c407f5b732f4e748_2.jpg' 二. 调用urllib库 impo ...