Hi
I am trying to make onTouchEnded work and after a couple examples i modified the helloworld to look like this:
#define __GAME1_SCENE_H__
#include "cocos2d.h"
USING_NS_CC;
class Game1 : public cocos2d::Layer
{
private:
LabelTTF* label;
public:
static cocos2d::Scene* createScene();
virtual bool init();
virtual void onEnter();
// a selector callback
void menuCloseCallback(cocos2d::Ref* pSender);
//touches handler
virtual bool onTouchBegan(Touch* touch, Event* event); // When touches are started.
virtual void onTouchEnded(Touch* touch, Event* event); // When touches are ended.
// implement the "static create()" method manually
CREATE_FUNC(Game1);
};
#endif // __GAME1_SCENE_H__
#include "Game1.h"
Scene* Game1::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::create();
// 'layer' is an autorelease object
auto layer = Game1::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 Game1::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Point 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(Game1::menuCloseCallback, this));
closeItem->setPosition(Point(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(Point::ZERO);
this->addChild(menu, 1);
/////////////////////////////
// 3. add your codes below...
// add a label shows "Hello World"
// create and initialize a label
label = LabelTTF::create("Hello World", "Arial", 24);
// position the label on the center of the screen
label->setPosition(Point(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height));
// add the label as a child to this layer
this->addChild(label, 1);
// add "HelloWorld" splash screen"
auto sprite = Sprite::create("HelloWorld.png");
// position the sprite on the center of the screen
sprite->setPosition(Point(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 Game1::onEnter(){
Layer::onEnter();
auto dispatcher = Director::getInstance()->getEventDispatcher();
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = CC_CALLBACK_2(Game1::onTouchBegan, this);
listener->onTouchEnded = CC_CALLBACK_2(Game1::onTouchEnded, this);
dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
void onTouchEnded(Touch* touch, Event* event){
Point location = touch->getLocationInView();
auto sprite = event->getCurrentTarget();
sprite->setPosition(0,0);
}
void Game1::menuCloseCallback(Ref* pSender)
{
Director::getInstance()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}
I am getting the following errors (LNK):
error LNK2001: unresolved external symbol “public: virtual bool __thiscall Game1::onTouchBegan(class cocos2d::Touch *,class cocos2d::Event *)” (?onTouchBegan@Game1@@UAE_NPAVTouch@cocos2d@@PAVEvent@3@@Z) D:\cocos2d-x-3.0rc0\tools\cocos2d-console\Game1\proj.win32\Game1.obj Game1
error LNK2001: unresolved external symbol “public: virtual void __thiscall Game1::onTouchEnded(class cocos2d::Touch *,class cocos2d::Event *)” (?onTouchEnded@Game1@@UAEXPAVTouch@cocos2d@@PAVEvent@3@@Z) D:\cocos2d-x-3.0rc0\tools\cocos2d-console\Game1\proj.win32\Game1.obj Game1
Also i am getting some warnings like:
warning LNK4098: defaultlib ‘libcmt.lib’ conflicts with use of other libs; use /NODEFAULTLIB:library D:\cocos2d-x-3.0rc0\tools\cocos2d-console\Game1\proj.win32\MSVCRTD.lib(cinitexe.obj) Game1
I am using Visual Studio Express 2012 and cocos2dx 3.0rc0
I can’t figure what is causing the errors, can someone plz help me understand what am i doing wrong?
Thanks