HelloWorldScene.cpp
bool HelloWorld::init()
{
if (!LayerColor::initWithColor(Color4B(255,255,255,255)))
{
return false;
}
auto item1 = MenuItemImage::create("btn-play-normal.png", "btn-play-selected.png", CC_CALLBACK_1(HelloWorld::doClick1, this));
auto item2 = MenuItemImage::create("btn-highscores-normal.png", "btn-highscores-selected.png", CC_CALLBACK_1(HelloWorld::doClick2, this));
auto item3 = MenuItemImage::create("btn-about-normal.png", "btn-about-selected.png", CC_CALLBACK_1(HelloWorld::doClick3, this));
auto menu = Menu::create(item1, item2, item3, NULL);
menu->alignItemsVertically();
this->addChild(menu);
return true;
}
void HelloWorld::doClick1(Ref* sender)
{
log("the first menu selected");
}
void HelloWorld::doClick2(Ref* sender)
{
log("the second menu selected");
}
void HelloWorld::doClick3(Ref* sender)
{
log("the third menu selected");
}
HelloWorldScene.h
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
class HelloWorld : public cocos2d::LayerColor
{
public:
static cocos2d::Scene* createScene();
virtual bool init();
// implement the "static create()" method manually
CREATE_FUNC(HelloWorld);
void doClick1(Ref* sender);
void doClick2(Ref* sender);
void doClick3(Ref* sender);
};
#endif // __HELLOWORLD_SCENE_H__
我正在学习的书中的源代码为void doClick1(Object* sender);
但是,当我编写相同的代码时,我的计算机上发生了一些错误。
为什么Ref*
没问题?