fixed #3185 support for html5.

This commit is contained in:
chengstory 2013-11-14 17:03:45 +08:00
parent 41975ba445
commit 6acf422f3b
3 changed files with 60 additions and 3 deletions

View File

@ -58,6 +58,51 @@ ComAttribute* ComAttribute::create(void)
return pRet;
}
void ComAttribute::setInt(const char *key, int value)
{
CCASSERT(key != NULL, "Argument must be non-nil");
_jsonDict->insertItem(key, value);
}
void ComAttribute::setFloat(const char *key, float value)
{
CCASSERT(key != NULL, "Argument must be non-nil");
_jsonDict->insertItem(key, value);
}
void ComAttribute::setBool(const char *key, bool value)
{
CCASSERT(key != NULL, "Argument must be non-nil");
_jsonDict->insertItem(key, value);
}
void ComAttribute::setCString(const char *key, const char *value)
{
CCASSERT(key != NULL, "Argument must be non-nil");
_jsonDict->insertItem(key, value);
}
int ComAttribute::getInt(const char *key) const
{
return _jsonDict->getItemIntValue(key, -1);
}
float ComAttribute::getFloat(const char *key) const
{
return _jsonDict->getItemFloatValue(key, -1.0f);
}
bool ComAttribute::getBool(const char *key) const
{
return _jsonDict->getItemBoolvalue(key, false);
}
const char* ComAttribute::getCString(const char *key) const
{
return _jsonDict->getItemStringValue(key);
}
JsonDictionary* ComAttribute::getDict() const
{
return _jsonDict;

View File

@ -47,6 +47,17 @@ protected:
public:
virtual bool init();
static ComAttribute* create(void);
void setInt(const char *key, int value);
void setFloat(const char *key, float value);
void setBool(const char *key, bool value);
void setCString(const char *key, const char *value);
int getInt(const char *key) const;
float getFloat(const char *key) const;
bool getBool(const char *key) const;
const char* getCString(const char *key) const;
JsonDictionary* getDict() const;
private:

View File

@ -39,7 +39,8 @@ void SceneController::onEnter()
_projectiles->retain();
((ComAudio*)(_owner->getComponent("Audio")))->playBackgroundMusic("background-music-aac.wav", true);
((ComAttribute*)(_owner->getComponent("ComAttribute")))->getDict()->insertItem("KillCount", 0);
((ComAttribute*)(_owner->getComponent("ComAttribute")))->setInt("KillCount", 0);
}
void SceneController::onExit()
@ -102,10 +103,10 @@ void SceneController::spriteMoveFinished(Node* sender)
void SceneController::increaseKillCount()
{
int nProjectilesDestroyed = ((ComAttribute*)(_owner->getComponent("ComAttribute")))->getDict()->getItemIntValue("KillCount", -1);
int nProjectilesDestroyed = ((ComAttribute*)(_owner->getComponent("ComAttribute")))->getInt("KillCount");
ComAttribute *p = (ComAttribute*)(_owner->getComponent("ComAttribute"));
p->getDict()->insertItem("KillCount", ++nProjectilesDestroyed);
p->setInt("KillCount", ++nProjectilesDestroyed);
if (nProjectilesDestroyed >= 5)
{