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

Author Topic: Displaying a Sprite doesn't work  (Read 2461 times)

0 Members and 1 Guest are viewing this topic.

cho9

  • Newbie
  • *
  • Posts: 3
    • View Profile
Displaying a Sprite doesn't work
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Displaying a Sprite doesn't work
« Reply #1 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 ;)
Laurent Gomila - SFML developer

Kingdom of Fish

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Displaying a Sprite doesn't work
« Reply #2 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.

 

anything