Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

SFML 2.0...sf::View do czego służy i czy pomoże.

Ostatnio zmodyfikowano 2012-11-06 15:48
Autor Wiadomość
ridic14
Temat założony przez niniejszego użytkownika
SFML 2.0...sf::View do czego służy i czy pomoże.
» 2012-11-02 14:32:03
Chodzi o to że polecono mi użyć sf::View w mojej grze aby większa rozdzielczość nie zmieniała poziomu trudności

Więc pytanie jest takie:
dlaczego w tym kodzie nic się nie rusza...:
C/C++
#include <SFML\Graphics.hpp>
#include <iostream>

int main()
{
    sf::Clock clock;
   
    sf::RenderWindow Window( sf::VideoMode( 800, 600, 32 ), "SFML Widoki" ); // Inicjacja okna
    Window.setFramerateLimit( 60 ); // Limit renderowania klatek na sekundê
    Window.setMouseCursorVisible( false );
   
    float dt; // Czas pomiędzy dwoma klatkami
   
    /*sf::Texture tex;
        tex.loadFromFile("tex.png");
        sf::Sprite Sprite(tex); // Sprite klocka
        Sprite.setColor(sf::Color::Red);
        Sprite.setPosition(300, 300); // Jego położenie*/
    sf::RectangleShape Sprite;
    Sprite.setFillColor( sf::Color::Blue );
    Sprite.setSize( sf::Vector2f( 200, 200 ) );
    Sprite.setPosition( 300, 200 );
   
    sf::CircleShape MousePointer;
    MousePointer.setFillColor( sf::Color::Red );
    MousePointer.setRadius( 5 );
    // Wskaźnik myszy
   
    while( Window.isOpen() ) // Pętla główna
    {
        // INNE
        sf::Event Event; // Zdarzenia
        sf::Time time = clock.getElapsedTime();
        dt = time.asSeconds();
        clock.restart(); // Aktualizacja czasu pomiêdzy dwoma klatkami
        float x = sf::Mouse::getPosition( Window ).x, y = sf::Mouse::getPosition( Window ).y; // Współrzędne myszki
        sf::View View = Window.getDefaultView();
       
        // WEJŚCIE
        while( Window.pollEvent( Event ) ) // Obsługa zdarzeń
        {
            if( Event.type == sf::Event::Closed ) Window.close(); // X - zamknj okno
           
            if(( Event.type == sf::Event::KeyReleased ) &&( Event.key.code == sf::Keyboard::Escape ) ) Window.close(); // ESC - zamknj okno
           
            if(( Event.type == sf::Event::KeyPressed ) &&( Event.key.code == sf::Keyboard::A ) ) View.zoom( 1.1f ); // Przybl
           
            if(( Event.type == sf::Event::KeyPressed ) &&( Event.key.code == sf::Keyboard::Z ) ) View.zoom( 0.9f ); // Oddal widok
           
            if(( Event.type == sf::Event::KeyReleased ) &&( Event.key.code == sf::Keyboard::Space ) ) // Wyświetl w konsoli informacje o widoku
            {
                std::cout << "INFORMACJE O WIDOKU: " << std::endl;
                std::cout << "center x: " << View.getCenter().x << std::endl;
                std::cout << "center y: " << View.getCenter().y << std::endl;
               
                std::cout << std::endl;
            }
           
        }
       
        // Jeżeli mysz zbliży się do krawędzi ekranu, to przesuń widok
        if( x <= 50 )
             View.move( - 200 * dt, 0 );
       
        if( x >= Window.getSize().x - 50 )
             View.move( 200 * dt, 0 );
       
        if( y <= 50 )
             View.move( 0, - 200 * dt );
       
        if( y >= Window.getSize().y - 50 )
             View.move( 0, 200 * dt );
       
        Window.draw( Sprite ); // Rysuj klocek
       
        MousePointer.setPosition( Window.convertCoords( sf::Vector2i(( int ) x,( int ) y ) ) ); // Konwertuj pozycje myszy i ustaw pozycję wskaźnika myszy
        Window.draw( MousePointer ); // Rysuj wskaźnik myszy
       
        Window.display(); // Wyświetl zawartość okna
        Window.clear(); // Wyczyść okno
    }
   
    return 0;
}
P-68195
akwes
» 2012-11-02 14:51:30
Lepiej poczytaj tutoriale SFML z 1.6. Obsługa sf::View zmieniła się jedynie w kilku detalach.
P-68198
ridic14
Temat założony przez niniejszego użytkownika
» 2012-11-05 22:25:53
Ale na samej klasie view nic nie zrobię zmieniło się wiele rzeczy które są podane w tutorialach(nic się nie da wymyślić)
P-68583
DejaVu
» 2012-11-05 22:49:11
Jeżeli masz kod, który działa poprawnie to dlaczego go nie prześledzisz?
P-68589
ridic14
Temat założony przez niniejszego użytkownika
» 2012-11-06 15:48:54
Trochę pomyślałem i... wyszło tak:
C/C++
#include <SFML\Graphics.hpp>
#include <iostream>

int main()
{
    sf::Clock clock;
   
    sf::RenderWindow App( sf::VideoMode( 800, 600, 32 ), "SFML Widoki" ); // Inicjacja okna
    App.setFramerateLimit( 60 ); // Limit renderowania klatek na sekundê
    App.setMouseCursorVisible( false );
   
    float dt; // Czas pomiędzy dwoma klatkami
   
    /*sf::Texture tex;
            tex.loadFromFile("tex.png");
            sf::Sprite Sprite(tex); // Sprite klocka
            Sprite.setColor(sf::Color::Red);
            Sprite.setPosition(300, 300); // Jego położenie*/
    sf::RectangleShape Sprite;
    Sprite.setFillColor( sf::Color::Blue );
    Sprite.setSize( sf::Vector2f( 200, 200 ) );
    Sprite.setPosition( 300, 200 );
   
    sf::CircleShape MousePointer;
    MousePointer.setFillColor( sf::Color::Red );
    MousePointer.setRadius( 5 );
    // Wskaźnik myszy
   
    sf::View View = App.getDefaultView();
   
    while( App.isOpen() ) // Pętla główna
    {
        // INNE
        sf::Event Event; // Zdarzenia
        sf::Time time = clock.getElapsedTime();
        dt = time.asSeconds();
        clock.restart(); // Aktualizacja czasu pomiêdzy dwoma klatkami
        float x = sf::Mouse::getPosition( App ).x, y = sf::Mouse::getPosition( App ).y; // Współrzędne myszki
       
       
        // WEJŚCIE
        while( App.pollEvent( Event ) ) // Obsługa zdarzeń
        {
            if( Event.type == sf::Event::Closed ) App.close(); // X - zamknj okno
           
            if(( Event.type == sf::Event::KeyReleased ) &&( Event.key.code == sf::Keyboard::Escape ) ) App.close(); // ESC - zamknj okno
           
            if(( Event.type == sf::Event::KeyPressed ) &&( Event.key.code == sf::Keyboard::A ) ) View.zoom( 1.1f ); // Przybl
           
            if(( Event.type == sf::Event::KeyPressed ) &&( Event.key.code == sf::Keyboard::Z ) ) View.zoom( 0.9f ); // Oddal widok
           
            if(( Event.type == sf::Event::KeyReleased ) &&( Event.key.code == sf::Keyboard::Space ) ) // Wyświetl w konsoli informacje o widoku
            {
                std::cout << "INFORMACJE O WIDOKU: " << std::endl;
                std::cout << "center x: " << View.getCenter().x << std::endl;
                std::cout << "center y: " << View.getCenter().y << std::endl;
               
                std::cout << std::endl;
            }
           
        }
       
        // Jeżeli mysz zbliży się do krawędzi ekranu, to przesuń widok
        if( x <= 50 )
             View.move( - 200 * dt, 0 );
       
        if( x >= App.getSize().x - 50 )
             View.move( 200 * dt, 0 );
       
        if( y <= 50 )
             View.move( 0, - 200 * dt );
       
        if( y >= App.getSize().y - 50 )
             View.move( 0, 200 * dt );
       
        App.setView( View );
        App.draw( Sprite ); // Rysuj klocek
       
        MousePointer.setPosition( App.convertCoords( sf::Vector2i(( int ) x,( int ) y ) ) ); // Konwertuj pozycje myszy i ustaw pozycję wskaźnika myszy
        App.draw( MousePointer ); // Rysuj wskaźnik myszy
       
        App.display(); // Wyświetl zawartość okna
        App.setView( App.getDefaultView() );
        App.clear(); // Wyczyść okno
    }
   
    return 0;
}

Teraz już "coś" się rusza tzn. drga... Edit(w czasie pisania zauważyłem): A już wiem o co chodzi sf::View View = App.getDefaultView(); trzeba przed pętlą główną

Działa...
P-68611
« 1 »
  Strona 1 z 1