我是初学者,用c ++ / sfml开发游戏。我不知道如何在任何特定情况下使任何形状或精灵消失? 例如: -
if(A-KEY-IS-PRESSED)
{
sprite.disappear
}
我想现在每个人都能理解我在说什么。我怎么能在sfml / c ++中做到这一点?
答案 0 :(得分:4)
在代码的某处,您有一个RenderWindow
,我们可以将其称为win
。而你正在做这样的事情:
win.draw(sprite);
要使精灵消失,只需不要这样做。
if(A-KEY-IS-PRESSED)
sprite_is_visible = false;
...
if (sprite_is_visible)
win.draw(sprite);
答案 1 :(得分:0)
如果您已经知道如何创建精灵(从列表中),这对您来说可能是一个很好的解决方案。
如果没有,那就告诉我,我会给你一个完整的代码示例。
删除Sprite的代码:
else if (event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Right)
{
sf::Vector2f mousecoords(mMainWindow.mapPixelToCoords(sf::Vector2i(event.mouseButton.x, event.mouseButton.y)));
EnemyList.remove_if([=](sf::Sprite newSprite){return newSprite.getGlobalBounds().contains(mousecoords); });
}