C
C#•12mo ago
Rizbones

How would i write this in sfml

class Disappear : public StaticPlatform
{
if (player collides with platform)
{
color = red;
if (player stands on platform for 3 seconds)
{
Destroy.Disappear;
}
}

class Disappear : public StaticPlatform
{
if (player collides with platform)
{
color = red;
if (player stands on platform for 3 seconds)
{
Destroy.Disappear;
}
}

6 Replies
Rizbones
RizbonesOP•12mo ago
im new to coding
SinFluxx
SinFluxx•12mo ago
isn't sfml c++?
Rizbones
RizbonesOP•12mo ago
yeah am i in the wrong place
SinFluxx
SinFluxx•12mo ago
🙂 someone may be able to answer you anyway but there's also $cpp
MODiX
MODiX•12mo ago
We're partnered with Together C & C++, check them out here: https://discord.gg/vnyVmAE
mjj
mjj•12mo ago
#include <SFML/Graphics.hpp> class Disappear : public sf::RectangleShape { public: Disappear() { setFillColor(sf::Color::Green); } void update(float deltaTime, sf::RectangleShape& player) { if (getGlobalBounds().intersects(player.getGlobalBounds())) { setFillColor(sf::Color::Red); // Check if player stands on platform for 3 seconds standingTime += deltaTime; if (standingTime >= 3.0f) { // Destroy the platform (remove it from the game) destroy(); } } else { // Reset standing time if not on the platform standingTime = 0.0f; setFillColor(sf::Color::Green); } } void destroy() { // Your logic to destroy or remove the platform goes here // For example: removeFromGame(); } private: float standingTime = 0.0f; }; int main() { sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Disappearing Platform"); sf::RectangleShape player(sf::Vector2f(50, 50)); player.setFillColor(sf::Color::Blue); player.setPosition(375, 500); Disappear platform; platform.setSize(sf::Vector2f(200, 20)); platform.setPosition(300, 400); sf::Clock clock; while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } float deltaTime = clock.restart().asSeconds(); // Update the platform and check for player collisions platform.update(deltaTime, player); window.clear(); window.draw(player); window.draw(platform); window.display(); } return 0; } Sfml is C++
Want results from more Discord servers?
Add your server