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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Tiseno

Pages: [1]
1
Graphics / 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

Pages: [1]
anything