vs2013生成lib
引擎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="">
最新文章
- 动态导入(import)和静态导入(import)的区别
- PHP检测每一段代码执行时间
- AC日记—— codevs 1031 质数环(搜索)
- Silverlight以列表显示数据库数据_DataGrid
- Golang 开发移动应用的OpenGL(Android为例)的渲染管线
- Bluetooth
- 用redis实现支持优先级的消息队列
- Java面试题之J2EE是什么
- mojo 关闭utf8
- windows 上搭建 sftp 服务器 --freesshd
- netflix zuul-simple-webapp.war在tomcat下启动
- Android 在Fragment中执行onActivityResult不被调用的简单解决方法
- happens-before规则和指令重排
- VisualStudio神级插件Resharper技巧基础入门到骨灰玩家使用全教程+Resharper性能优化
- java字符串根据正则表达式让单词首字母大写
- liteUploader上传控件的封装使用
- Jacob 调用金税系统
- Windows,远程计算机:X.X.X.X,这可能是由于CredSSP加密Oracle修正
- js滚动条如何缓慢的回到顶部?
- MyGeneration使用概述