if(GetKeyState(VK_SPACE) && Player1.canFire == true)
{
Player1.canFire = false;
Player1.hasFired = true;
Bullet Bullet1((Player1.Xpos + (Player1.Skin->GetWidth() / 2)),
Player1.Ypos - ProjectileSkin->GetHeight() );
}
if(Player1.hasFired = true)
{
Bullet1.Projectile->CopyTo(m_Screen, Bullet1.m_xPos, Bullet1.m_yPos);
Bullet1.m_yPos -= 5;
}
在我说
Bullet1.Projectile->CopyTo
的地方,我得到的错误是未定义Bullet1
,但是我在上面的if块中实例化了它。我究竟做错了什么? 最佳答案
您的Bullet1
到达第9行时已超出范围。您需要将Bullet1
变量声明移到if
语句之外。
但是,如果您仍然需要初始化if
,那么我根本看不出放置第二个Bullet1
语句的意义。所以,
if(GetKeyState(VK_SPACE) && Player1.canFire == true)
{
Player1.canFire = false;
Player1.hasFired = true;
Bullet Bullet1((Player1.Xpos + (Player1.Skin->GetWidth() / 2)),
Player1.Ypos - ProjectileSkin->GetHeight() );
Bullet1.Projectile->CopyTo(m_Screen, Bullet1.m_xPos, Bullet1.m_yPos);
Bullet1.m_yPos -= 5;
}