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.


Messages - snakypoutz

Pages: [1]
1
Graphics / Re: unsmooth movement/remnant sprite when using a view
« on: April 04, 2015, 04:58:23 pm »
What if you set the view before drawing the character ?

God thank you so much it works. I should have thought of that.

2
Graphics / Re: unsmooth movement/remnant sprite when using a view
« on: April 04, 2015, 04:24:12 pm »
They are up to date.
I have a 144hz monitor so I thought maybe this could be an issue, but I tried on my laptop and the results were the same.

I honnestly don't know what's wrong.

I did an other test. Instead of moving the character and having a view centered on it, I got rid of the view and move the map arround the character, leaving it in the center.
With this method there is absolutely no visual artifact. So it confirms that the problem comes from using a view.

3
Graphics / unsmooth movement/remnant sprite when using a view
« on: April 03, 2015, 07:15:02 pm »
Hello

can you tell me what's wrong with this code? When I move the character in any direction, it is displayed twice. There is like a transparent remnant of the sprite.

It does not appear on screenshot so I took a picture instead


If I remove the setVerticalSync it will be smooth, but from time to time the remnant will appear for like a fraction of second.

It seems to be caused by the view. Before using one, movements were smooth.

#include <SFML\Graphics.hpp>
#include <SFML\Audio.hpp>


int main()
{
        sf::RenderWindow window(sf::VideoMode(640, 480), "Test");
        window.setMouseCursorVisible(false);
        window.setVerticalSyncEnabled(true);

        sf::View view = window.getView();

        sf::Texture texCharacter;
        if (!texCharacter.loadFromFile("character.png"))
                return -1;
        sf::Sprite character;
        character.setTexture(texCharacter);
       

        sf::Texture texMap;
        if (!texMap.loadFromFile("map.png"))
                return -1;
        sf::Sprite map;
        map.setTexture(texMap);
        map.setPosition(sf::Vector2f(-640, -480));

        sf::Music music;
        if (!music.openFromFile("music.ogg"))
                return -1;
       
        sf::SoundBuffer buffer;
        if (!buffer.loadFromFile("sound.wav"))
                return -1;

        sf::Sound sound;
        sound.setBuffer(buffer);

        music.play();
        music.setLoop(true);


        while (window.isOpen())
        {

                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::LControl))
                                sound.play();

                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                                character.move(-32, 0);
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                                character.move(+32, 0);
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                                character.move(0, -32);
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                                character.move(0, +32);
                }

                window.clear();

                window.draw(map);
                window.draw(character);

                view.setCenter(character.getPosition());
                window.setView(view);

                window.display();
        }

        return 0;
}
 

Thanks for your help.

Pages: [1]