9.13总结

    xiaoxiao2022-06-23  43

    道具的实现,运用文本api,在场景中显示出金币的数量 for (int i = 0; i < ItemVec.size(); i++){ if (aa->getBoundingBox().intersectsRect(ItemVec.at(i)->getBoundingBox())){ coin1 += 1; ItemVec.at(i)->removeFromParent(); ItemVec.eraseObject(ItemVec.at(i)); char string[20] = { 0 }; sprintf(string, "coin:%d", coin1); auto label2 = (Label*)getChildByTag(12); label2->setString(string); } } 飞机和生命值道具的碰撞,然后删除 for (int j = 0; j < HpVec.size(); j++){ if (abc->getBoundingBox().intersectsRect(HpVec.at(j)->getBoundingBox())){ HpVec.at(j)->removeFromParent(); HpVec.eraseObject(HpVec.at(j)); heroHp += 100; } } 飞机hp的边界要注意,否则会出现打不死boss ,而且我机不死亡的现象  if (heroHp > 0){  for (int j = 0; j < BultVec.size(); j++){  if (abc->getBoundingBox().intersectsRect(BultVec.at(j)->getBoundingBox())){  heroHp-=10;  BultVec.at(j)->removeFromParent();  BultVec.eraseObject(BultVec.at(j));  char string[10] = {0};  sprintf(string, "HP:%d", heroHp);  auto label1 = (Label*)getChildByTag(10);  label1->setString(string);  CCLOG("%d", heroHp);  }  } }  if (heroHp<=0){  //this->unscheduleAllSelectors();  auto scene = GameScene2::createScene();  Director::getInstance()->replaceScene(TransitionFade::create(2, scene, Color3B::WHITE));  } boss的文本,扣血,也同样要注意边界 for (int i = 0; i < ddd.size(); i++) { for (j = 0; j < aaa.size(); j++) { if (ddd.at(i)->getBoundingBox().intersectsRect(aaa.at(j)->getBoundingBox())) { bosshp -=10; //d1->remove4(ddd.at(i)); a1->remove(aaa.at(j)); char string[20] = { 0 }; sprintf(string, "bosshp :%d", bosshp); auto label3 = (Label*)getChildByTag(8); label3->setString(string); if (bosshp <= 0){ d1->remove4(ddd.at(i)); bosshp = 10000; }
    转载请注明原文地址: https://ju.6miu.com/read-1123093.html

    最新回复(0)