SFML community forums

Help => Graphics => Topic started by: cho9 on July 18, 2009, 03:00:56 pm

Title: Displaying a Sprite doesn't work
Post by: cho9 on July 18, 2009, 03:00:56 pm
Hi,

This code:

Code: [Select]
#include <iostream>
#include <SFML/Graphics.hpp>

int main()
{
    int x = 0;
    int y = 0;
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(1440, 900, 32), "SFML Graphics");

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Clear the screen (fill it with black color)
        if(y == 0)
        {
            App.Clear();
            y = 1;
        }

        sf::Image Image;
        if (!Image.LoadFromFile("sprite.tga"))
        {
            if(x == 0)
            {
                std::cout << "Bild konnte nicht geladen werden\n";
            }
            x = 1;
        }

        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}


displays an empty window, but it should display a sprite in the window.

Thank you for your help.
Title: Displaying a Sprite doesn't work
Post by: Laurent on July 18, 2009, 05:21:00 pm
This code loads an image from the disk at every loop, there's no sprite. You should read the tutorials ;)
Title: Displaying a Sprite doesn't work
Post by: Kingdom of Fish on July 19, 2009, 03:53:27 am
And you really should name your variables better... I don't understand what you where thinking with the x and y variables.