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

Author Topic: Render window pointer and sprites  (Read 2110 times)

0 Members and 3 Guests are viewing this topic.

Jiggered

  • Newbie
  • *
  • Posts: 9
    • View Profile
Render window pointer and sprites
« on: August 31, 2012, 12:37:08 pm »
I'm trying to load sprites through the renderwindow that I'm pointing to, it seems to work fine without errors, but when loading a sprite all I get is the white dot. I've tried everything I can think of, and still it refuses to render.

.h
class Invador
{
public:
Invador(sf::RenderWindow& window) :
        m_window(window)
                {}

    float Draw()
    {
                imag.LoadFromFile("sprite.png");
                sprite.SetPosition(10,1);
        m_window.Draw(sprite);
                return 0;
    }

private:
    sf::RenderWindow& m_window;
        sf::Image imag;
        sf::Sprite sprite;
       
};
 

main
int main()
{
sf::RenderWindow window(sf::VideoMode(SC_WIDTH, SC_HEIGHT, 32), "SFML Window");

Invador Draw(window);

while (window.IsOpened())
     {
         sf::Event Event;
         while (window.GetEvent(Event))
         {
             if (Event.Type == sf::Event::Closed)
                 window.Close();
         }
 
                 float elapsedTime = window.GetFrameTime();

                 /*cout << elapsedTime * 100 << endl;*/

         window.Clear();
                 Draw.Draw();

         window.Display();
     }
        return EXIT_SUCCESS;
}
 

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Render window pointer and sprites
« Reply #1 on: August 31, 2012, 12:51:54 pm »
Quote from: Jiggered
imag.LoadFromFile("sprite.png");
sprite.SetPosition(10,1);
m_window.Draw(sprite);

 ???
First off, you load the texture file in every frame - and then you don't even use it. You load a texture and don't assign it to the sprite. Or you're leaving relevant code out that we can't see.

Apart from that, why does "Draw" return a float value of zero?

Also, you might want to update to SFML 2 soon, the release candidate can be downloaded already. 1.6 is not really supported anymore.
« Last Edit: August 31, 2012, 12:53:40 pm by pdinklag »
JSFML - The Java binding to SFML.

Jiggered

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Render window pointer and sprites
« Reply #2 on: August 31, 2012, 01:08:13 pm »
I did originally assign it to the sprite, but I JUST realised, I assigned it in the wrong order, I assigned before the image was even loaded.

I'm not sure how to load the sprite inside my class file, but outside my function, I just get errors

So now the sprite loads, just not sure how to load it outside of functions.


 

anything