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

Author Topic: Sprite not showing when Shape are being drawn, SFML 2.0  (Read 5540 times)

0 Members and 1 Guest are viewing this topic.

Tiseno

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Sprite not showing when Shape are being drawn, SFML 2.0
« on: November 06, 2012, 04:21:21 pm »
I have a Texture which i load to a Sprite and i have 2 Shapes (In the attached code CircleShape but RectangleShape will result in the same error) and when i draw those 2 the sprite will show only the first frame. After the first frame the sprite will not be drawn any more. If i draw only one, the sprite will be drawn. If i draw two Shapes and then remove one of them to only draw one of them, the Sprite will not draw.

The code has some basic movement on the sprite and control of drawing the 2 Shapes or not to demonstrate the dissapearance of the sprite. Frameratelimit is set to 1 to show the first frame clearly. There is need for a "texture.png" to draw the sprite:
#include "stdafx.h"
#include <SFML/Graphics.hpp>

using namespace sf;

int main(){

    RenderWindow window(VideoMode(1400, 800, 32), "SFML FTW", Style::Default);
    window.setFramerateLimit(1);

    CircleShape fooShape(150.0f, 50);
    CircleShape barShape(50.0f, 30);
    fooShape.setPosition(100.0f, 100.0f);
    barShape.setPosition(0.0f, 0.0f);
   
    Texture aTexture;
    aTexture.loadFromFile("texture.png");
    Sprite aSprite;
    aSprite.setTexture(aTexture);
    aSprite.setPosition(1000.0f, 600.0f);

    bool drawFoo = false;
    bool drawBar = false;

    while(window.isOpen()){
        Event Event;
        while(window.pollEvent(Event)){
            if(Event.type == Event.KeyPressed){
                if(Event.key.code == Keyboard::A){
                    aSprite.move(-20.0f, 0.0f);
                }else if(Event.key.code == Keyboard::D){
                    aSprite.move(20.0f, 0.0f);      
                }else if(Event.key.code == Keyboard::W){
                    aSprite.move(0.0f, -20.0f);    
                }else if(Event.key.code == Keyboard::S){
                    aSprite.move(0.0f, 20.0f);      
                }else if(Event.key.code == Keyboard::O){
                    if(drawFoo) drawFoo = false;
                    else        drawFoo = true;
                }else if(Event.key.code == Keyboard::P){
                    if(drawBar) drawBar = false;
                    else        drawBar = true;
                }
            }
        }      
        window.clear(Color(200, 100, 40));
        if(drawFoo)
            window.draw(fooShape);
        if(drawBar)
            window.draw(barShape);
        window.draw(aSprite);
        window.display();
    }
    return EXIT_SUCCESS;
}

I'm using SFML 2.0, Visual C++ 2010 Express and my graphics card is a XFX Radeon 5750

EDIT: Updated the code according to the new build of SFML 2.0
« Last Edit: November 06, 2012, 08:03:28 pm by Tiseno »

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Re: Sprite not showing when Shape are being drawn, SFML 2.0
« Reply #1 on: November 06, 2012, 06:14:17 pm »
What build of SFML are you using? How old is it, because I notice the case is not correct.

window.SetFramerateLimit(1);

is now:

window.setFramerateLimit(1);

...and many other things. So I guess you are using an old version?
SFML 2.1

Tiseno

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Sprite not showing when Shape are being drawn, SFML 2.0
« Reply #2 on: November 06, 2012, 08:05:45 pm »
What build of SFML are you using? How old is it, because I notice the case is not correct.

window.SetFramerateLimit(1);

is now:

window.setFramerateLimit(1);

...and many other things. So I guess you are using an old version?

Correct, I was using an old version of SFML 2.0 and have now updated my library and changed the code accordingly, but the program behaves exactly the same...

Did you try my code, and if so, is it working like it should?

cire

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Re: Sprite not showing when Shape are being drawn, SFML 2.0
« Reply #3 on: November 07, 2012, 12:05:27 am »

Tiseno

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Sprite not showing when Shape are being drawn, SFML 2.0
« Reply #4 on: November 07, 2012, 01:30:49 am »
Appears to be the same issue as http://en.sfml-dev.org/forums/index.php?topic=9561.0

Yes I saw that post but i only read the first page, it seems they discovered the problem with Sprite aswell, sorry for making the post, will report my new findings in that thread instead.