A few days ago I compiled SFML 2.2 for Android and already made a few small Apps. Now I'm trying to create something bigger, but there's a problem: The application needs a relatively long time to start up and react, for example when I rotate the phone. I think my phone is fast enough to run the App smoothly( I have an OnePlus One with a Qualcomm Snapdragon 801 and 3GB RAM), and other Apps created with SFML (For example Kroniax) run smoothly. If I compile the code on my PC, it runs fast, so I guess my code is just very resource-heavy.
The following code reproduces the problem:
#include <SFML/Graphics.hpp>
inline void adjustCharacterSize(sf::Text& text, const sf::Vector2u& windowSize, unsigned short factor)
{
while(text.getGlobalBounds().width < windowSize.x - windowSize.x / factor && text.getCharacterSize() < 500)
text.setCharacterSize(text.getCharacterSize() + 1);
while(text.getGlobalBounds().width > windowSize.x - windowSize.x / factor && text.getCharacterSize() > 10)
text.setCharacterSize(text.getCharacterSize() - 1);
}
int main(int argc, char *argv[])
{
sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "", sf::Style::Fullscreen);
window.setVerticalSyncEnabled(true);
sf::Font font;
font.loadFromFile("Lato-Light.ttf");
sf::Text text;
text.setFont(font);
text.setString("Hello World!");
text.setColor(sf::Color::Green);
text.setCharacterSize(100);
adjustCharacterSize(text, window.getSize(), 4);
text.setPosition(150, 150);
sf::View view = window.getDefaultView();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
}
if (event.type == sf::Event::Resized)
{
view.setSize(event.size.width, event.size.height);
view.setCenter(event.size.width/2, event.size.height/2);
adjustCharacterSize(text, window.getSize(), 4);
window.setView(view);
}
}
window.clear();
window.draw(text);
window.display();
}
}
I already found out that the function 'adjustCharacterSize' seems to be responsible for the slow behavior, but I don't know why. I modified the function several times, but with no success.
Any ideas oft what I could do?