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

Author Topic: AlexxanderX problems...  (Read 24282 times)

0 Members and 1 Guest are viewing this topic.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11008
    • View Profile
    • development blog
    • Email
Re: AlexxanderX problems...
« Reply #45 on: September 13, 2014, 10:50:01 pm »
Use integer numbers for your view moving and make sure all your tiles are on integer coordinates.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

AlexxanderX

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • AlexanderX
Re: AlexxanderX problems...
« Reply #46 on: September 14, 2014, 04:12:30 pm »
Wow... using a simple trick:
view.setCenter(sf::Vector2f(sf::Vector2i(playerCenter));
the problem is resolved. Thanks a lot! ;D
Here you can find my blog and tutorials about SFML - http://alexanderx.net/ (died...) - http://web.archive.org/web/20160110002847/http://alexanderx.net/

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: AlexxanderX problems...
« Reply #47 on: September 14, 2014, 07:48:10 pm »
That works, yes, but, I'd personally use something like this:
view.setCenter(std::floor(playerCenter.x), std::floor(playerCenter.y));

AlexxanderX

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • AlexanderX
Re: AlexxanderX problems...
« Reply #48 on: February 08, 2015, 08:58:39 pm »
I have Linux Mint 17.1 and Mesa Mesa 10.1.3(stable) and when run an app is a frozen transparent window. The green circle example also doesn't work.

I have downgraded from Mesa 10.6.0-devel in the hope of resolving the problem and after reboot I have rebuilt the sfml and straight forward I have compiled the green circle example and it was working. But then I have rebuilt the Thor library and after that I compiled a project and the frozen transparent window appeared. And I go back to recompile the green circle example and the same frozen transparent window showed. Please some help.
« Last Edit: February 08, 2015, 09:16:19 pm by AlexxanderX »
Here you can find my blog and tutorials about SFML - http://alexanderx.net/ (died...) - http://web.archive.org/web/20160110002847/http://alexanderx.net/

AlexxanderX

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • AlexanderX
Re: AlexxanderX problems...
« Reply #49 on: February 17, 2015, 03:25:30 pm »
I have the following code for the camera of my game:
// Updating the player
m_player.update(frame, m_quadTree);

// Getting the center position of the player
sf::Vector2f playerCenter = m_player.getCenter();

// Setting the center of the map(show only visible tiles)
m_map.setPlayerCenter(playerCenter);

// Setting the view to the center of the player
m_view.setCenter(std::floor(playerCenter.x), std::floor(playerCenter.y));

The problem is that when I jump only on vertical axis( only up arrow) the tiles are like trembling, and when i jump on diagonals( up arrow + left/right arrow) also the player start to tremble. Some tips please?

Here is a video with the problem:

https://www.youtube.com/watch?v=S9fzD4eJ5IA

EDIT: Setting the view center to the exact position resolv the problem, but also activate another problem discussed here.
EDIT2: Problem resolved: the player position is now also set with std::floor()
« Last Edit: February 17, 2015, 05:22:33 pm by AlexxanderX »
Here you can find my blog and tutorials about SFML - http://alexanderx.net/ (died...) - http://web.archive.org/web/20160110002847/http://alexanderx.net/

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11008
    • View Profile
    • development blog
    • Email
Re: AlexxanderX problems...
« Reply #50 on: February 17, 2015, 05:27:10 pm »
I don't really see the problem. Since you move the screen at the same time as your player moves, every slight change will apply to the screen as well.
What you might think about is to have a certain rectangle in which the player can move freely without moving the screen. Though that might still cause the "trembling" I fail to see. :D
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

AlexxanderX

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • AlexanderX
Re: AlexxanderX problems...
« Reply #51 on: February 19, 2015, 03:22:37 pm »
The problem was from the player: I was not setting his position to an integer one. Thanks for tip :D
Here you can find my blog and tutorials about SFML - http://alexanderx.net/ (died...) - http://web.archive.org/web/20160110002847/http://alexanderx.net/

AlexxanderX

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • AlexanderX
Re: AlexxanderX problems...
« Reply #52 on: July 21, 2015, 06:04:14 pm »
Hello :D I have a problem: I'm getting high CPU usage with this code and I don't know what I'm doing wrong:
#include <SFML/Graphics.hpp>

int main()
{
        sf::RenderWindow window({800, 600}, "My window");

        sf::Time m_timePerFrame = sf::seconds(1.0f / 60.0f);
        sf::Time m_timeSinceLastUpdate = sf::Time::Zero;

        sf::Clock m_clock;
    while (window.isOpen())
    {
                sf::Time m_frame = m_clock.restart();
                m_timeSinceLastUpdate += m_frame;

                while (m_timeSinceLastUpdate >= m_timePerFrame)
                {
                        sf::Event event;
                while (window.pollEvent(event))
                {
                    if (event.type == sf::Event::Closed)
                        window.close();
                }

                        m_timeSinceLastUpdate -= m_timePerFrame;
                }

                window.clear();

                window.display();
    }

    return 0;
}

If instead of all the manual frame limiting I use window.setFramerateLimit(60) everything works fine - 0% cpu usage, but with my above code I'm getting high CPU usage. Please some help.
Here you can find my blog and tutorials about SFML - http://alexanderx.net/ (died...) - http://web.archive.org/web/20160110002847/http://alexanderx.net/

kitteh-warrior

  • Guest
Re: AlexxanderX problems...
« Reply #53 on: July 21, 2015, 06:22:59 pm »
If you don't instruct the system to wait, would you expect it to? ;)
Use the sf::sleep to let the thread wait.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: AlexxanderX problems...
« Reply #54 on: July 21, 2015, 07:34:42 pm »
Window.setFramerateLimit(60);
That's the solution. What more to say?
If you ask the CPU to work as had as it can then it will. If you ask it to take some breaks it will. It's really simple.
« Last Edit: July 21, 2015, 08:03:15 pm by Jesper Juhl »

 

anything