当我尝试运行游戏时,我目前遇到以下错误的问题。我试着理解以下错误的含义,但我发现很难理解。我相信有不止一个错误,但我不知道在哪里看。我很想得到你的帮助!
[armeabi] Compile++ thumb: MyGame_shared <= BallSprite.cpp
[armeabi] Compile++ thumb: MyGame_shared <= Character.cpp
[armeabi] StaticLibrary : libcocos2d.a
[armeabi] StaticLibrary : libcocostudio.a
[armeabi] StaticLibrary : libcocosbuilder.a
[armeabi] StaticLibrary : libcocos3d.a
jni/../../../Classes/Character.cpp:26:5: error: prototype for 'int Character::getTurnCount()' does not match any in class 'Character'
int Character::getTurnCount()
^
In file included from /Users/michael/Desktop/CocoFolder/Puzzle/cocos2d/cocos/3d/../base/CCAsyncTaskPool.h:28:0,
from /Users/michael/Desktop/CocoFolder/Puzzle/cocos2d/cocos/3d/../cocos2d.h:41,
from jni/../../../Classes/Character.h:4,
from jni/../../../Classes/Character.cpp:1:
/Users/michael/Desktop/CocoFolder/Puzzle/cocos2d/cocos/3d/../platform/CCPlatformMacros.h:153:25: error: candidate is: virtual int Character::getTurnCount() const
public: virtual varType get##funName(void) const;\
^
jni/../../../Classes/Character.h:26:5: note: in expansion of macro 'CC_PROPERTY'
CC_PROPERTY(int, _turnCount, TurnCount);
^
jni/../../../Classes/BallSprite.cpp:62:27: error: prototype for 'BallSprite::PositionIndex BallSprite::getPositionIndex()' does not match any in class 'BallSprite'
BallSprite::PositionIndex BallSprite::getPositionIndex()
^
In file included from /Users/michael/Desktop/CocoFolder/Puzzle/cocos2d/cocos/3d/../base/CCAsyncTaskPool.h:28:0,
from /Users/michael/Desktop/CocoFolder/Puzzle/cocos2d/cocos/3d/../cocos2d.h:41,
from jni/../../../Classes/BallSprite.h:4,
from jni/../../../Classes/BallSprite.cpp:1:
/Users/michael/Desktop/CocoFolder/Puzzle/cocos2d/cocos/3d/../platform/CCPlatformMacros.h:153:25: error: candidate is: virtual BallSprite::PositionIndex BallSprite::getPositionIndex() const
public: virtual varType get##funName(void) const;\
^
jni/../../../Classes/BallSprite.h:53:5: note: in expansion of macro 'CC_PROPERTY'
CC_PROPERTY(PositionIndex, _positionIndex, PositionIndex);
^
make: *** [obj/local/armeabi/objs-debug/MyGame_shared/__/__/__/Classes/BallSprite.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [obj/local/armeabi/objs-debug/MyGame_shared/__/__/__/Classes/Character.o] Error 1
make: Leaving directory `/Users/michael/Desktop/CocoFolder/Puzzle/proj.android-studio/app'
Error running command, return code: 2.
角色代码
#include "Character.h"
USING_NS_CC;
Character::Character()
: _hp(0)
, _maxHp(0)
, _attack(0)
, _element(Element::None)
, _turnCount(0)
, _remainingTurn(0)
{
}
Character* Character::create()
{
Character *pRet = new Character();
pRet->autorelease();
return pRet;
}
int Character::getTurnCount()
{
return _turnCount;
}
void Character::setTurnCount(int turnCount)
{
_turnCount = turnCount;
_remainingTurn = _turnCount;
}
float Character::getHpPercentage()
{
return _hp * 100.f / _maxHp;
}
bool Character::isAttackTurn()
{
_remainingTurn--;
if (_remainingTurn <= 0)
{
_remainingTurn = _turnCount;
return true;
}
return false;
}
int Character::getDamage(int ballCount, int chainCount, Character* attacker, Character* defender)
{
float baseDamage = ballCount / 3.0 * 100;
float chainBonus = powf(1.1, chainCount - 1);
float elementBonus = getElementBonus(attacker->getElement(), defender->getElement());
return baseDamage * chainBonus * elementBonus;
}
float Character::getElementBonus(Element attackElement, Element defenseElement)
{
switch (attackElement)
{
case Element::Fire:
{
switch (defenseElement)
{
case Element::Wind:return 2;
case Element::Water:return 0.5;
default:return 1;
}
break;
}
case Element::Water:
{
switch (defenseElement)
{
case Element::Fire:return 2;
case Element::Wind:return 0.5;
default:return 1;
}
break;
}
case Element::Wind:
{
switch (defenseElement)
{
case Element::Water:return 2;
case Element::Wind:return 0.5;
default:return 1;
}
break;
}
case Element::Holy:
{
switch (defenseElement)
{
case Element::Shadow:return 2;
default:return 1;
}
break;
}
case Element::Shadow:
{
switch (defenseElement)
{
case Element::Holy:return 2;
default:return 1;
}
break;
}
default:
{
return 1;
}
}
}
字符标题
class Character : public cocos2d::Ref
{
public:
enum class Element
{
Fire,
Water,
Wind,
Holy,
Shadow,
None,
};
protected:
int _remainingTurn;
CC_SYNTHESIZE(int, _hp, Hp);
CC_SYNTHESIZE(int, _maxHp, MaxHp);
CC_SYNTHESIZE(int, _attack, Attack);
CC_SYNTHESIZE(Element, _element, Element);
CC_PROPERTY(int, _turnCount, TurnCount);
public:
Character();
static Character* create();
float getHpPercentage();
bool isAttackTurn();
static int getDamage(int ballCount, int chainCount, Character* attacker, Character* defender);
protected:
static float getElementBonus(Element attackElement, Element defenseElement);
};
#endif
BallSprite.cpp
#include "BallSprite.h"
USING_NS_CC;
BallSprite::BallSprite()
: _removedNo(0)
, _checkedX(false)
, _checkedY(false)
, _fallCount(0)
, _positionIndex(0, 0)
{
}
BallSprite* BallSprite::create(BallType type, bool visible)
{
BallSprite *pRet = new BallSprite();
if (pRet && pRet->init(type, visible))
{
pRet->autorelease();
return pRet;
}
else
{
delete pRet;
pRet = nullptr;
return nullptr;
}
}
bool BallSprite::init(BallType type, bool visible)
{
if (!Sprite::initWithFile(getBallImageFilePath(type)))
return false;
_ballType = type;
setVisible(visible);
return true;
}
void BallSprite::resetParams()
{
_removedNo = 0;
_checkedX = false;
_checkedY = false;
_fallCount = 0;
}
void BallSprite::resetPosition()
{
setPosition(getPositionForPositionIndex(_positionIndex));
}
void BallSprite::getPositionIndex()
{
return _positionIndex;
}
void BallSprite::setPositionIndex(PositionIndex positionIndex)
{
_positionIndex = positionIndex;
setTag(generateTag(_positionIndex));
}
void BallSprite::setPositionIndexAndChangePosition(PositionIndex positionIndex)
{
setPositionIndex(positionIndex);
resetPosition();
}
void BallSprite::removingAndFallingAnimation(int maxRemovedNo)
{
removingAnimation(maxRemovedNo);
fallingAnimation(maxRemovedNo);
}
void BallSprite::removingAnimation(int maxRemovedNo)
{
if (_removedNo > 0)
{
auto delay1 = DelayTime::create(ONE_ACTION_TIME * (_removedNo - 1));
auto fade = FadeTo::create(ONE_ACTION_TIME, 0);
auto delay2 = DelayTime::create(ONE_ACTION_TIME * (maxRemovedNo - _removedNo));
auto removeSelf = RemoveSelf::create(false);
runAction(Sequence::create(delay1, fade, delay2, removeSelf, nullptr));
}
}
void BallSprite::fallingAnimation(int maxRemovedNo)
{
if (_fallCount > 0)
{
setPositionIndex(PositionIndex(_positionIndex.x, _positionIndex.y - _fallCount));
auto delay = DelayTime::create(ONE_ACTION_TIME * maxRemovedNo);
auto show = Show::create();
auto move = MoveTo::create(ONE_ACTION_TIME, getPositionForPositionIndex(getPositionIndex()));
runAction(Sequence::create(delay, show, move, nullptr));
}
}
std::string BallSprite::getBallImageFilePath(BallType type)
{
switch (type)
{
case BallType::Red: return "red.png";
case BallType::Blue: return "blue.png";
default: return "pink.png";
}
}
Point BallSprite::getPositionForPositionIndex(PositionIndex positionIndex)
{
return Point(BALL_SIZE * (positionIndex.x - 0.5) + 1,
BALL_SIZE * (positionIndex.y - 0.5) + 1);
}
int BallSprite::generateTag(PositionIndex positionIndex)
{
return positionIndex.x * 10 + positionIndex.y;
}
BallSprite标题
#include "cocos2d.h"
#define BALL_SIZE 106
#define ONE_ACTION_TIME 0.2
class BallSprite : public cocos2d::Sprite
{
public:
enum class BallType
{
Blue,
Red,
Green,
Yellow,
Purple,
Pink,
};
struct PositionIndex
{
PositionIndex()
{
x = 0;
y = 0;
}
PositionIndex(int _x, int _y)
{
x = _x;
y = _y;
}
int x;
int y;
};
BallSprite();
static BallSprite* create(BallType type, bool visible);
virtual bool init(BallType type, bool visible);
CC_SYNTHESIZE(int, _removedNo, RemovedNo);
CC_SYNTHESIZE(bool, _checkedX, CheckedX);
CC_SYNTHESIZE(bool, _checkedY, CheckedY);
CC_SYNTHESIZE(int, _fallCount, FallCount);
CC_SYNTHESIZE_READONLY(BallType, _ballType, BallType);
CC_PROPERTY(PositionIndex, _positionIndex, PositionIndex);
void setPositionIndexAndChangePosition(PositionIndex positionIndex);
void resetParams();
void resetPosition();
void removingAndFallingAnimation(int maxRemovedNo);
static std::string getBallImageFilePath(BallType type);
static cocos2d::Point getPositionForPositionIndex(PositionIndex positionIndex);
static int generateTag(PositionIndex positionIndex);
protected:
void removingAnimation(int maxRemovedNo);
void fallingAnimation(int maxRemovedNo);
};
#endif
答案 0 :(得分:1)
CC_PROPERTY(int, _turnCount, TurnCount);
虚拟方法定义应该是这样的,因为在声明中它是常量。
int Character::getTurnCount() const
{
return _turnCount;
}
在getter方法的返回类型中存在问题,应该是这样的。
CC_PROPERTY(PositionIndex, _positionIndex, PositionIndex);
PositionIndex BallSprite::getPositionIndex() const
{
return _positionIndex;
}
编辑
您无法直接访问PositionIndex
,请将其与BallSprite
一起使用
BallSprite::PositionIndex BallSprite::getPositionIndex() const
{
return _positionIndex;
}