两个炮台切换的笔记(局限性)

if (battery2 == NULL&&battery1 != NULL&&str == "right"){    //增加炮台等级
		//this->addBattery(sss);
		battery2 = Sprite::create("paotai2.png");
		battery2->setPosition(Vec2(visibleSize.width / 2 + 90, visibleSize.height / 2 - 340));
		this->addChild(battery2, 9);
		if (battery1 != NULL){
			battery1->removeFromParent();
			battery1 = NULL;
		}
	}
	else if (battery2 != NULL&&battery1 == NULL&&str == "left"){  //减少炮台等级
		//this->cutBattery(sss);
		battery1 = Sprite::create("paotai1.png");
		battery1->setPosition(Vec2(visibleSize.width / 2 + 90, visibleSize.height / 2 - 340));
		addChild(battery1, 9);
		if (battery2 != NULL){
			battery2->removeFromParent();
			battery2 = NULL;
		}
	}

你可能感兴趣的:(c++)