SFML 2.0...sf::View do czego służy i czy pomoże.
Ostatnio zmodyfikowano 2012-11-06 15:48
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...: #include <SFML\Graphics.hpp> #include <iostream>
int main() { sf::Clock clock; sf::RenderWindow Window( sf::VideoMode( 800, 600, 32 ), "SFML Widoki" ); Window.setFramerateLimit( 60 ); Window.setMouseCursorVisible( false ); float dt; 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 ); while( Window.isOpen() ) { sf::Event Event; sf::Time time = clock.getElapsedTime(); dt = time.asSeconds(); clock.restart(); float x = sf::Mouse::getPosition( Window ).x, y = sf::Mouse::getPosition( Window ).y; sf::View View = Window.getDefaultView(); while( Window.pollEvent( Event ) ) { if( Event.type == sf::Event::Closed ) Window.close(); if(( Event.type == sf::Event::KeyReleased ) &&( Event.key.code == sf::Keyboard::Escape ) ) Window.close(); if(( Event.type == sf::Event::KeyPressed ) &&( Event.key.code == sf::Keyboard::A ) ) View.zoom( 1.1f ); if(( Event.type == sf::Event::KeyPressed ) &&( Event.key.code == sf::Keyboard::Z ) ) View.zoom( 0.9f ); if(( Event.type == sf::Event::KeyReleased ) &&( Event.key.code == sf::Keyboard::Space ) ) { 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; } } 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 ); MousePointer.setPosition( Window.convertCoords( sf::Vector2i(( int ) x,( int ) y ) ) ); Window.draw( MousePointer ); Window.display(); Window.clear(); } return 0; } |
|
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. |
|
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ć) |
|
DejaVu |
» 2012-11-05 22:49:11 Jeżeli masz kod, który działa poprawnie to dlaczego go nie prześledzisz? |
|
ridic14 Temat założony przez niniejszego użytkownika |
» 2012-11-06 15:48:54 Trochę pomyślałem i... wyszło tak: #include <SFML\Graphics.hpp> #include <iostream>
int main() { sf::Clock clock; sf::RenderWindow App( sf::VideoMode( 800, 600, 32 ), "SFML Widoki" ); App.setFramerateLimit( 60 ); App.setMouseCursorVisible( false ); float dt; 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 ); sf::View View = App.getDefaultView(); while( App.isOpen() ) { sf::Event Event; sf::Time time = clock.getElapsedTime(); dt = time.asSeconds(); clock.restart(); float x = sf::Mouse::getPosition( App ).x, y = sf::Mouse::getPosition( App ).y; while( App.pollEvent( Event ) ) { if( Event.type == sf::Event::Closed ) App.close(); if(( Event.type == sf::Event::KeyReleased ) &&( Event.key.code == sf::Keyboard::Escape ) ) App.close(); if(( Event.type == sf::Event::KeyPressed ) &&( Event.key.code == sf::Keyboard::A ) ) View.zoom( 1.1f ); if(( Event.type == sf::Event::KeyPressed ) &&( Event.key.code == sf::Keyboard::Z ) ) View.zoom( 0.9f ); if(( Event.type == sf::Event::KeyReleased ) &&( Event.key.code == sf::Keyboard::Space ) ) { 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; } } 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 ); MousePointer.setPosition( App.convertCoords( sf::Vector2i(( int ) x,( int ) y ) ) ); App.draw( MousePointer ); App.display(); App.setView( App.getDefaultView() ); App.clear(); } 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... |
|
« 1 » |