关于Cocos2d-x中根据分数增加游戏难度的方法
1.GameScene.h中声明一些分数边界值
1 //level提升所需的分数 2 enum LevelUp_Score 3 { 4 Level1Up_Score = 5, 5 Level2Up_Score = 10, 6 Level3Up_Score = 15, 7 Level4Up_Score = 20 8 };
2.在移动的Baby对象类的.cpp文件的update方法中写,每一帧都会执行update方法
1 //让生成的Baby实例对象不断地往左边移动,超出屏幕就消失,好像有了这个就不用再在Block和Star的定义下面写一个用来消失的update函数了 2 void Baby::update(float dt){ 3 //log("wo zai baby update limian1"); 4 m_score=GameScene::sharedGameLayer()->getScore(); 5 //log("wo zai baby update limian2"); 6 //m_score=GameScene::getScore(); 7 //根据到达的分数,设置LEVEL 8 if (m_score > GameScene::LevelUp_Score::Level1Up_Score && m_score < GameScene::LevelUp_Score::Level2Up_Score) 9 { 10 //m_level = LEVEL2; 11 setPositionX(getPositionX() - 6); 12 } 13 else if (m_score > GameScene::LevelUp_Score::Level2Up_Score && m_score < GameScene::LevelUp_Score::Level3Up_Score) 14 { 15 //m_level = LEVEL3; 16 setPositionX(getPositionX() - 8); 17 } 18 else if (m_score > GameScene::LevelUp_Score::Level3Up_Score && m_score < GameScene::LevelUp_Score::Level4Up_Score) 19 { 20 //m_level = LEVEL4; 21 setPositionX(getPositionX() - 10); 22 } 23 else if (m_score > GameScene::LevelUp_Score::Level4Up_Score) 24 { 25 //m_level = LEVEL5; 26 setPositionX(getPositionX() - 12); 27 } 28 else 29 { 30 setPositionX(getPositionX() - 6); 31 //setPositionX(getPositionX() - 6); 32 } 33 34 if (getPositionX()<-this->getContentSize().width) { 35 unscheduleUpdate(); 36 removeFromParent(); 37 } 38 }