Welcome, Guest. Please login or register. Did you miss your activation email?

Recent Posts

Pages: [1] 2 3 ... 10
1
SFML projects / Re: FiveBlocksFall - My first SFML videogame
« Last post by Hapax on Today at 12:15:11 am »
This code doesn't seem too bad. If it works, it shouldn't matter anyway! ;D

With that said, you could probably do both event loops as just one and just change what is drawn by the current time (whether it's in the splash section or the fade out section).
2
General / Re: making menu with different files
« Last post by Hapax on March 09, 2026, 11:58:23 pm »
It sounds like you want to write a program (menu) that can execute another program (game)...

I would question this design.
It's likely that the main menu (or similar) would be accessible from within the game (paused, for example) anyway but, even if not, you'll likely be returning to the menu after the game has been played.
So, it's probably better to include the menu "program" and game "program" into just one executable.

You can still access files from within C++ so you can always load main menu (or other menu) data from a separate file, if required.


With that being said, if you do need to launch another executable from within your program, you can do this but you'll need OS-specific code.
3
DotNet / Re: Window by default set to lower right corner
« Last post by eXpl0it3r on March 03, 2026, 12:58:28 pm »
Wondering if this is somewhat related to the this GitHub issue we recently got: https://github.com/SFML/SFML.Net/issues/297
4
Graphics / Re: Font file isnt found
« Last post by eXpl0it3r on March 03, 2026, 07:38:38 am »
The error message on the console should tell you, where sf::Font expected the font to be located.

Paths are loaded relative to the working directory. If you launch it from VS it would be by default the project location. If you run it from the explorer, it would be next to the executable.

Note that Microsoft's license doesn't allow you to redistribute Arial. I suggest you pick an open font such as DejaVuSans or similar.
5
SFML projects / FiveBlocksFall - My first SFML videogame
« Last post by michelemura on March 02, 2026, 10:46:04 pm »
This piece of C++ code is the first which runs after the game has been loaded:

void _showSplashScreen() {
    sf::RenderWindow windowSplash(sf::VideoMode(512, 512), "FiveBlocksFall", sf::Style::None);

    // Load your splash texture
    sf::Texture splashTexture;
    splashTexture.loadFromFile("assets/pics/splash_screen.png");
    sf::Sprite splashSprite(splashTexture);
    splashSprite.setPosition(0.f, 0.f);

    // Clock to measure the 3 seconds
    sf::Clock clock;

    // --- MAIN SPLASH LOOP (3 seconds) ---
    while (windowSplash.isOpen())
    {
        sf::Event event;
        while (windowSplash.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                windowSplash.close();
        }

        // Close splash after 3 seconds
        if (clock.getElapsedTime().asSeconds() > 3.f)
            break; // or switch to your main game state

        windowSplash.clear(sf::Color::Black);
        windowSplash.draw(splashSprite);
        windowSplash.display();
    }

    // --- FADE OUT (1 second) ---
    sf::RectangleShape fadeRect(sf::Vector2f(512.f, 512.f));
    fadeRect.setFillColor(sf::Color(0, 0, 0, 0)); // fully transparent
   
    sf::Clock fadeClock;
    while (windowSplash.isOpen()) {
        sf::Event event;
       
        while (windowSplash.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                windowSplash.close();
        }
       
        float t = fadeClock.getElapsedTime().asSeconds();
        if (t > 1.f) break; // Alpha goes from 0 → 255 over 1 second
        sf::Uint8 alpha = static_cast<sf::Uint8>(255 * (t / 1.f));
        fadeRect.setFillColor(sf::Color(0, 0, 0, alpha));
       
        windowSplash.draw(splashSprite);
        windowSplash.draw(fadeRect);
        windowSplash.display();
    }
}

The game has been published on itch.io but there's always space for improvement..
What do you think about this fade-out routine?
6
Graphics / Re: Font file isnt found
« Last post by vokazoo on March 02, 2026, 10:03:45 pm »
The code itself doesn't cause the error you're getting, this is almost certainly the result of project misconfiguration. Have you tried putting Arial.ttf in the same folder as the executable? What's the project structure like?

Try passing the absolute path of the font file (for example: sf::Font font("C:\\Users\\username\\ProjectName\\Arial2.ttf"); ), if that works the problem is confirmed.
7
Graphics / Font file isnt found
« Last post by jjasome11 on March 02, 2026, 05:41:32 pm »
I am using Microsoft Visual Studio version 18.3.2, I am attempting to recreate pong in c++, and everything up until I have tried to use text has worked perfectly fine. I downloaded Arial.ttf and put it into my project directory, but when I use sf::Font font("Arial.ttf"), trying to run it gives me the no such file was found in the directory error. I am on a console application file, using ctrl+f5 in the Visual Studio to build the exe and run it.

The following is the code for the game
#include <iostream>
#include <SFML/Graphics.hpp>
#include <chrono>
#include <thread>
#include <cmath>

int main()
{

    using namespace sf::Literals;

    int score = 0;

    sf::RenderWindow window(sf::VideoMode({ 800, 800 }), "PONG", sf::Style::None);
    sf::RectangleShape PaddleL({ 20.f, 160.f });
    sf::RectangleShape paddleR({ 20.f, 160.f });
        sf::CircleShape ball(10.f);
        sf::Font font("Arial.ttf");
        sf::Text scoretext(font);

        scoretext.setCharacterSize(30);
        scoretext.setFillColor(sf::Color::White);
        scoretext.setPosition({ 400.f, 10.f });
        scoretext.setString(std::to_string(score));

        ball.setOrigin({ 10.f, 10.f });
        ball.setPosition({ 400.f, 400.f });

        PaddleL.setOrigin({ 10.f, 80.f });
        paddleR.setOrigin({ 10.f, 80.f });

        PaddleL.setPosition({ 30.f, 400.f});
        paddleR.setPosition({ 770.f, 400.f });

    PaddleL.setFillColor(sf::Color::White);
        paddleR.setFillColor(sf::Color::White);

    bool PaddleLup = false;
    bool PaddleLdown = false;
    bool paddleRup = false;
    bool paddleRdown = false;
    bool play = false;

    auto right_vertical = paddleR.getPosition().y;
    auto left_vertical = PaddleL.getPosition().y;

    int right_top = right_vertical - 80;
    int right_bottom = right_vertical + 80;
    int left_top = left_vertical - 80;
    int left_bottom = left_vertical + 80;

    std::srand(std::time(nullptr));
    float start_angle = std::rand() % 360;
        start_angle = start_angle * 3.1415 / 180;
    float start_velocity = 0.2f;
       

    while (window.isOpen())
    {

        while (const std::optional event = window.pollEvent())
        {
            if (event->is<sf::Event::Closed>())
                window.close();

            if (const auto* Keypressed = event->getIf<sf::Event::KeyPressed>()) {
                if (Keypressed->scancode == sf::Keyboard::Scan::W)
                    PaddleLup = true;
                else if (Keypressed->scancode == sf::Keyboard::Scan::S)
                    PaddleLdown = true;
                if (Keypressed->scancode == sf::Keyboard::Scan::Up)
                    paddleRup = true;
                else if (Keypressed->scancode == sf::Keyboard::Scan::Down)
                    paddleRdown = true;
                if (Keypressed->scancode == sf::Keyboard::Scan::Space) {
                    std::srand(std::time(nullptr));
                    if (play == false) {
                        play = true;
                    }
                    else {
                        play = false;
                        ball.setPosition({ 400.f, 400.f });
                        start_angle = 3.1415;
                    }
                }
               
            }
            if (const auto* KeyReleased = event->getIf<sf::Event::KeyReleased>()) {
                if (KeyReleased->scancode == sf::Keyboard::Scan::W)
                    PaddleLup = false;
                else if (KeyReleased->scancode == sf::Keyboard::Scan::S)
                    PaddleLdown = false;
                if (KeyReleased->scancode == sf::Keyboard::Scan::Up)
                    paddleRup = false;
                else if (KeyReleased->scancode == sf::Keyboard::Scan::Down)
                    paddleRdown = false;
            }

        }
        if (ball.getPosition().y <= 10 or ball.getPosition().y >= 790)
            start_angle = -start_angle;

        if (play) {
            if (PaddleLup and PaddleL.getPosition().y >= 80)
                PaddleL.move({ 0, -0.5 });
            else if (PaddleLdown and PaddleL.getPosition().y <= 720)
                PaddleL.move({ 0, 0.5 });
            if (paddleRup and paddleR.getPosition().y >= 80)
                paddleR.move({ 0, -0.5 });
            else if (paddleRdown and paddleR.getPosition().y <= 720)
                paddleR.move({ 0, 0.5 });

            right_vertical = paddleR.getPosition().y;
            left_vertical = PaddleL.getPosition().y;
            right_top = right_vertical - 80;
            right_bottom = right_vertical + 80;
            left_top = left_vertical - 80;
            left_bottom = left_vertical + 80;

            if ((ball.getPosition().x - 10 <= 40 and ball.getPosition().x >= 20.f) and (ball.getPosition().y >= left_top and ball.getPosition().y <= left_bottom)) {
               start_angle = 3.1415 - start_angle;
                                start_angle += (std::rand() % 12 - 6) * 3.1415 / 180;
                start_velocity = start_velocity * 1.02f;
                                std::cout << start_velocity << " " << start_angle << std::endl;

            }
            else if ((ball.getPosition().x + 10 >= 760 and ball.getPosition().x <= 780) and (ball.getPosition().y >= right_top and ball.getPosition().y <= right_bottom)) {
                start_angle = 3.1415 - start_angle;
                                start_angle += (std::rand() % 12 - 6) * 3.1415 / 180;
                                start_velocity = start_velocity * 1.02f;
                                std::cout << start_velocity <<  " " << start_angle << std::endl;
            }
           
            float sine = sin(start_angle);
            float cosine = cos(start_angle);
            ball.move({ cosine * start_velocity, sine * start_velocity});
        }

                right_vertical = paddleR.getPosition().y;
                left_vertical = PaddleL.getPosition().y;
                right_top = right_vertical - 80;
                right_bottom = right_vertical + 80;
                left_top = left_vertical - 80;
                left_bottom = left_vertical + 80;

        scoretext.setString(std::to_string(score));

        window.clear();
        window.draw(PaddleL);
                window.draw(paddleR);
                window.draw(ball);
                window.draw(scoretext);
        window.display();
       
    }
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started:
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
 

removing lines 18-24, 146, and 152 makes the code run perfectly fine, those are the lines related to text.
8
SFML projects / Re: Screenshot Thread
« Last post by michelemura on March 01, 2026, 11:41:07 pm »
Hi everybody! This is the screenshot of a game in progress

9
Graphics / SFML 3.0 - Font corrupted when window closed
« Last post by CATDev on February 27, 2026, 03:39:03 pm »
I'm developing a simple project in SFML 3.0 with FMOD, currently when I close the render window (but not the console window) I get an exception thrown "Run-Time Check Failure #2 - Stack around the variable 'font' was corrupted." after return in main.cpp is called

I'm unsure why this is occurring with the font variable as when I look for the error online it is typically caused by writing past the max size of an array. I'm a bit of a noob with memory management so I couldn't think of any solutions or causes myself.

Any help greatly appreciated!

int main()
{
    //prepare window
    sf::Vector2u screen_size = sf::Vector2u(480, 640);

    sf::RenderWindow window(sf::VideoMode({ screen_size.x, screen_size.y }), "CMP407 Assessment Project)");
    window.setFramerateLimit(60);       //Request 60 frames per second

    //randomise seed
    std::srand(std::time(NULL));

    //audio manager for FMOD
    AudioManager audioManager;
    // Input class
    Input in;

    Level level(&window, &in, &audioManager, sf::Vector2i(screen_size.x, screen_size.y));

    // Initialise objects for delta time
    sf::Clock clock;
    float deltaTime;


    //Text
    sf::Font font;
    if (!font.openFromFile("../Fonts/Orbitron.ttf")) {
        std::cerr << "ERROR LOADING FONT";
    }

    sf::Text scoreText(font, "Test", 24);
    scoreText.setPosition(sf::Vector2f(24, 24));
    sf::Text livesText(font, "Test", 24);
    livesText.setPosition(sf::Vector2f(24, 64));

    audioManager.startEvent();

    printf("Hello World");

    while (window.isOpen()) {
        while (const std::optional event = window.pollEvent())
        {
            if (event->is<sf::Event::Closed>())
            {
                window.close();
               
            }
            else if (const auto* keyPressed = event->getIf<sf::Event::KeyPressed>())
            {
                if (keyPressed->scancode == sf::Keyboard::Scancode::Escape)
                    window.close();
               
            }
            level.handleEvents(event);
        }

        deltaTime = clock.restart().asSeconds();
        level.inputs(deltaTime);
        level.update(deltaTime);
        scoreText.setString("Score: " + std::to_string(level.getScore()));
        livesText.setString("Lives: " + std::to_string(level.getLives()));

        audioManager.updateFmod();

#pragma endregion
        //Render
        window.clear();
        level.render();
        window.draw(scoreText);
        window.draw(livesText);
        window.display();
    }

    return 0;
}
 
10
General / making menu with different files
« Last post by voptik123 on February 26, 2026, 08:26:58 am »
im new to sfml and is it possible to make main menu with a cpp file for menu thats links you to the game file ???
Pages: [1] 2 3 ... 10
anything