关于cocos2d-x
#include "HelloWorldScene.h"#include "cocos-ext.h"
using namespace cocos2d::extension;
using namespace cocos2d;
CCScene* HelloWorld::scene()
{
CCScene * scene = NULL;
do
{
// 'scene' is an autorelease object
scene = CCScene::create();
CC_BREAK_IF(! scene);
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();
CC_BREAK_IF(! layer);
// add layer as a child to scene
scene->addChild(layer);
} while (0);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
bool bRet = false;
do
{
//////////////////////////////////////////////////////////////////////////
// super init first
//////////////////////////////////////////////////////////////////////////
CC_BREAK_IF(! CCLayer::init());
//正常状态下的按钮图片
CCScale9Sprite*btnNormal=CCScale9Sprite::create("button.png");
//单击状态下的按钮图片
CCScale9Sprite*btnDown=CCScale9Sprite::create("buttonHighlighted.png");
//按钮标题
CCLabelTTF*title=CCLabelTTF::create("Touch Me!","Maker Felt",30);
//创建按钮,按钮的大小会根据标题自动调整
CCControlButton*controlBtn=CCControlButton::create(title,btnNormal);
//当鼠标处于按下并点中按钮时,则触发一次
controlBtn->addTargetWithActionForControlEvents(this,
cccontrol_selector(HelloWorld::touchDown),
CCControlEventTouchDown);
//设置按钮按下时的图片
controlBtn->setBackgroundSpriteForState(btnDown,CCControlStateSelected);
controlBtn->setPosition(ccp(200,200));
//controlBtn->setPreferredSize(CCSize(200,200));////强制设置按钮大小,如果按钮标题大小超过这个范围,则会自动扩大//
this->addChild(controlBtn);
bRet=true;
}while(0);
return bRet;
}
/*CCScale9Sprite*nineGirl=CCScale9Sprite::create("button.png");
nineGirl->setContentSize(CCSize(200,100));
nineGirl->setPosition(ccp(200,200));
this->addChild(nineGirl);
bRet=true;
}while(0);
return bRet;
}*/
//////////////////////////////////////////////////////////////////////////
// add your codes below...
//////////////////////////////////////////////////////////////////////////
// 1. Add a menu item with "X" image, which is clicked to quit the program.
// Create a "close" menu item with close icon, it's an auto release object.
/*CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback));
CC_BREAK_IF(! pCloseItem);
// Place the menu item bottom-right conner.
pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));
// Create a menu with the "close" menu item, it's an auto release object.
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
CC_BREAK_IF(! pMenu);
// Add the menu to HelloWorld layer as a child layer.
this->addChild(pMenu, 1);
// 2. Add a label shows "Hello World".
// Create a label and initialize with string "Hello World".
CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);
CC_BREAK_IF(! pLabel);
// Get window size and place the label upper.
CCSize size = CCDirector::sharedDirector()->getWinSize();
pLabel->setPosition(ccp(size.width / 2, size.height - 50));
// Add the label to HelloWorld layer as a child layer.
this->addChild(pLabel, 1);
// 3. Add add a splash screen, show the cocos2d splash image.
CCSprite* pSprite = CCSprite::create("HelloWorld.png");
CC_BREAK_IF(! pSprite);
// Place the sprite on the center of the screen
pSprite->setPosition(ccp(size.width/2, size.height/2));
// Add the sprite to HelloWorld layer as a child layer.
this->addChild(pSprite, 0);
bRet = true;
} while (0);
return bRet;
}*/
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
// "close" menu item clicked
CCDirector::sharedDirector()->end();
}
头文件:
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
#include "cocos-ext.h"
#include "SimpleAudioEngine.h"
using namespace cocos2d::extension;
class HelloWorld : public cocos2d::CCLayer
{
public:
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
// there's no 'id' in cpp, so we recommand to return the exactly class pointer
static cocos2d::CCScene* scene();
// a selector callback
void menuCloseCallback(CCObject* pSender);
// implement the "static node()" method manually
CREATE_FUNC(HelloWorld);
private:
void touchDown(CCObject*pSender,CCControlEvent event);
};
#endif // __HELLOWORLD_SCENE_H__
>HelloWorldScene.obj : error LNK2001: 无法解析的外部符号 "private: void __thiscall HelloWorld::touchDown(class cocos2d::CCObject *,unsigned int)" (?touchDown@HelloWorld@@AAEXPAVCCObject@cocos2d@@I@Z)
1>D:\光盘代码\cocos2d-x书籍源码\Cocos2d-x游戏开发之旅\MutouCocos2dxAllDemos\MutouCocos2dxAllDemos\Chapter4_2_Scale9Sprite\Chapter4_2_Scale9Sprite\Debug.win32\Chapter4_2_Scale9Sprite.win32.exe : fatal error LNK1120: 1 个无法解析的外部命令
1>
我在它的属性-输入里面加入了libExtensions.lib,但还是显示无法显示的外部符号,想请教一下