如何在 c++/sfml 2.1 中使任何精灵消失
How to make any sprite dissapear in c++/sfml 2.1?
我是一个初学者,正在开发一个用c ++/sfml的游戏。我不知道如何在任何特定条件下使任何形状或精灵消失?
例如:-
if(A-KEY-IS-PRESSED)
{
sprite.disappear
}
我想现在每个人都能理解我在说什么。如何在 sfml/c++ 中做到这一点?
在你的代码中的某个地方,你有一个RenderWindow
,我们称之为win
。你正在做这样的事情:
win.draw(sprite);
要让精灵消失,就不要那样做。
if(A-KEY-IS-PRESSED)
sprite_is_visible = false;
...
if (sprite_is_visible)
win.draw(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); });
}
相关文章:
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 如何在不产生任何垃圾的情况下获得C中的像素
- 为什么我不能在 C++ 中的特定函数重载中调用同一函数的任何其他重载?
- C++映射有2个键,这样任何1个键都可以用来获取值
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- RtlCaptureStackBackTrace未捕获任何帧
- 链表c++插入,所有情况都已检查,但没有任何工作
- C++模板函数,用于比较任何无符号整数和有符号整数
- Arduino millis() - millis() 怎么能等于 0 以外的任何东西?
- 尝试摆脱任何堆内存分配
- 是否有任何C++功能可以对地图进行排序?
- 打印时有二叉树问题.用户输入不打印任何内容
- 共享指针和具有自定义删除程序的唯一指针之间的语法差异背后的任何原因
- 在C++行尾写一个分号或多个分号是否会改变任何内容
- C++类型特征,以查看是否可以<uint32_t>对类型"K"的任何变量调用"static_cast(k)"
- OpenGL 着色器不绘制任何东西 - 糟糕的精灵类
- COCOS2D-X:从另一个线程中加载精灵,任何模式
- 如何在 c++/sfml 2.1 中使任何精灵消失
- c++快板绘图精灵(即使没有任何循环)减慢图像速度