我正在尝试将我的 iPhone 应用程序移植到 Windows 8,但这条线有问题(它是 Objective-c):
[self schedule:@selector(fire:)];
c++ 上的等价物应该是:
this->schedule(schedule_selector(AirScene::fire));
其中 AirScene 是我的班级的名称,但 Visual Studio 2012 返回此错误:
error C2064: term does not evaluate to a function taking 1 arguments
因此,换句话说,找不到函数 schedule(selector)。这很奇怪,因为我对 unschedule 方法没有任何问题,请问您有什么想法吗?
编辑:AirScene.h
#include "cocos2d.h"
#include "Box2D\Box2D.h"
#include "AirSceneDelegate.h"
class AirScene : public cocos2d::CCLayer {
public:
AirScene::~AirScene(void);
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
static cocos2d::CCScene* scene();
LAYER_NODE_FUNC(AirScene);
//Methods
void selectSpriteForTouch(cocos2d::CCPoint touchLocation);
cocos2d::CCPoint checkPuckPosition(cocos2d::CCPoint newPosition);
void panForTranslation(cocos2d::CCPoint translation);
void updateQuestion(string question);
void restoreScene();
void enableScreensaver();
void disableScreensaver(cocos2d::CCPoint touchPosition);
//Setters
void setDelegate(AirSceneDelegate *delegate);
private:
// Init
void initBackground(cocos2d::CCSize winSize);
void initPuck(cocos2d::CCSize winSize, cocos2d::CCPoint position);
void initHoles(cocos2d::CCSize winSize);
void initQuestion(cocos2d::CCSize winSize);
// Methods
void fire(cocos2d::ccTime dt = 0);
void updateHoles(cocos2d::ccTime dt);
void validateVote(bool isPositiveVote);
float getVelocity();
// Attributes
...
//Delegate
AirSceneDelegate* _delegate;
};
空中场景.cpp
#include <iostream>
#include "AirScene.h"
USING_NS_CC;
#pragma region Delete
AirScene::~AirScene(void)
{
///TODO : DELETE ALL
delete(_delegate);
_delegate = 0;
}
#pragma endregion Delete
#pragma region Init
CCScene* AirScene::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::node();
// 'layer' is an autorelease object
AirScene *layer = AirScene::node();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool AirScene::init()
{
// Super Init
if (!CCLayer::init())
return false;
//Init Attributes
screenSaverMode = false;
hasVoted = false;
schedule = false;
_delegate = 0;
_selSprite = NULL;
//Create World
b2Vec2 gravity = b2Vec2(0, 0);
_world = new b2World(gravity);
CCSize size = CCDirector::sharedDirector()->getWinSize();
//Inits
AirScene::initBackground(size);
AirScene::initPuck(size, ccp(512, 200));
AirScene::initHoles(size);
AirScene::initQuestion(size);
return true;
}
// Init Background and set walls
void AirScene::initBackground(CCSize winSize)
{
...
}
/** Init Puck : create puck body and shape */
void AirScene::initPuck(CCSize winSize, CCPoint position)
{
...
}
void AirScene::initHoles(CCSize winSize)
{
...
}
// Set Question Label
void AirScene::initQuestion(CCSize winSize)
{
...
}
#pragma endregion Init
#pragma region Private
void AirScene::fire(ccTime dt)
{
_world->Step(dt, 8, 8);
//CCSprite *ballData = ((CCSprite *)_body->GetUserData())
((CCSprite *)_body->GetUserData())->setPosition(ccp(_body->GetPosition().x * PTM_RATIO, _body->GetPosition().y * PTM_RATIO));
_puckShadow->setPosition(ccp(((CCSprite *)_body->GetUserData())->getPosition().x + 2, ((CCSprite *)_body->GetUserData())->getPosition().y - 2));
if (screenSaverMode)
AirScene::updateHoles(0);
}
//Ajust Glow Effect and Validate Vote
void AirScene::updateHoles(cocos2d::ccTime dt)
{
...
}
float AirScene::getVelocity()
{
...
}
void AirScene::validateVote(bool isPositiveVote)
{
...
}
#pragma endregion Private
#pragma region Public
void AirScene::selectSpriteForTouch(CCPoint touchLocation)
{
...
}
// Check if the puck is not outside the view
CCPoint AirScene::checkPuckPosition(CCPoint newPosition)
{
...
}
// Move Puck
void AirScene::panForTranslation(CCPoint translation)
{
...
}
// Update Question
void AirScene::updateQuestion(string question)
{
...
}
void AirScene::restoreScene()
{
...
}
void AirScene::enableScreensaver()
{
screenSaverMode = true;
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
//Unschedule actions
this->unscheduleAllSelectors();
//Delete Puck
CCPoint puckPosition = _puck->getPosition();
_puck->removeAllChildrenWithCleanup(true);
_puck->removeFromParentAndCleanup(true);
_puckShadow->removeAllChildrenWithCleanup(true);
_puckShadow->removeFromParentAndCleanup(true);
_world->DestroyBody(_body);
delete(_puck);
delete(_puckShadow);
//RecreatePuck
this->initPuck(winSize, ccp(512, 200));
//Impulse
_body->SetLinearVelocity(b2Vec2(0, 0));
/** ERROR IS CAUSED BY THIS LINE */
this->schedule(schedule_selector(AirScene::fire));
}
void AirScene::disableScreensaver(cocos2d::CCPoint touchPosition)
{
}
#pragma endregion Public
#pragma region Getters & Setters
void AirScene::setDelegate(AirSceneDelegate *delegate)
{
_delegate = delegate;
}
#pragma endregion Getters & Setters