我的Player类定义如下:
" Player.h"
#ifndef PLAYER_h
#define PLAYER_h
#include "cocos2d.h"
USING_NS_CC;
class Player: public Sprite {
public:
Player();
~Player();
private:
Sprite *playerSprite;
__String name;
int maxHP;
int currHP;
int maxMP;
int currMP;
int maxEXP;
int currEXP;
};
#endif
和" Player.cpp":
#include "Player.h"
我想在
上初始化int maxHP,int maxMP .. etcPlayer* myPlayer = Player::create();
使用
这样的参数覆盖:: create()函数的正确方法是什么// create(int maxHP, int currHP, int maxMP, int currMP, int maxEXP, int currEXP)
Player* myPlayer = Player::create(100, 100, 100, 100, 100, 100);
可以用吗?
答案 0 :(得分:1)
您可以重载create
(具有相同名称但签名不同的多个函数)。
class Player : public Sprite {
public:
static Player* create(int maxHP, int currHP, int maxMP, int currMP, int maxEXP, int currEXP) {
Player* p = Player::create();
p->maxHP = maxHP;
// etc ...
return p;
}
}