Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <SFML/Graphics.hpp> int main() { sf::RenderWindow app(sf::VideoMode(1000, 1000), "SFML Shapes"); for (int i=0; i<1000; i++) { app.Clear(); app.Draw(sf::Shape::Circle(i, i, 1, sf::Color::White)); app.Display(); } return 0; } |
Alter Hase
C-/C++-Quelltext |
|
1 2 3 4 |
while (App.IsOpened()) { // Bewege irgendwas } |
Alter Hase
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#include <SFML/Graphics.hpp> #include <iostream> #include <windows.h> int main() { sf::RenderWindow App(sf::VideoMode(800, 600), "SFML Shapes"); while (App.IsOpened()) { sf::Event Event; while (App.GetEvent(Event)) { if (Event.Type == sf::Event::Closed) App.Close(); } sf::Shape tmpShape = sf::Shape::Circle(0, 0, 1, sf::Color::White); App.Display(); for (int i=0; i<200; i++) { tmpShape.SetPosition(i, i); App.Draw(tmpShape); Sleep(1000); } } return EXIT_SUCCESS; } |
Alter Hase
Zitat
Like every drawable object in SFML, shape objects inherit the common functions to set their position, rotation, scale, color and blending mode.
Polygon.SetColor(sf::Color(255, 255, 255, 200));
Polygon.Move(300, 300);
Polygon.Scale(3, 2);
Polygon.Rotate(45);
Finally, drawing a shape is also like any other drawable object in SFML :
App.Draw(Polygon);
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include <SFML/Graphics.hpp> #include <iostream> #include <windows.h> int main() { sf::RenderWindow App(sf::VideoMode(800, 600), "SFML Shapes"); while (App.IsOpened()) { sf::Event Event; while (App.GetEvent(Event)) { if (Event.Type == sf::Event::Closed) App.Close(); } sf::Shape tmpShape = sf::Shape::Circle(0, 0, 1, sf::Color::White); for (int i=0; i<200; i++) { tmpShape.SetPosition(i, i); App.Draw(tmpShape); App.Display(); Sleep(25); } } return EXIT_SUCCESS; } |
Alter Hase
C-/C++-Quelltext |
|
1 2 |
float fPos; sf::Shape::Circle(0,0,1,sf::Color::White); |
C-/C++-Quelltext |
|
1 2 3 4 5 |
fpos+=25.0f*App.GetFrameTime(); //(oder welcher wert auch immer) tmpShape.SetPosition(fPos,fPos); App.Draw(tmpShape); App.Display(); // Sleep(25); das kannst du dann weglassen |
Zitat von »"dev_null"«
Hi, danke für den Tipp jetzt habe ich nur noch kleines Problem, und zwar die Linie die Zittert die ganze zeit, also es ist kein gerader strich, sondert die zittert ganz komisch, kann das nicht richtig erklären. Wenn die Schleife fertig, sieht das so aus als wenn sich der letzte Punkt immer zurück und wieder forwärts bewegt. Das ganze sieht auch extrem verpixelt aus. Habe das jetzt so gemacht:
C-/C++-Quelltext
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #include <SFML/Graphics.hpp> #include <iostream> #include <windows.h> int main() { sf::RenderWindow App(sf::VideoMode(800, 600), "SFML Shapes"); while (App.IsOpened()) { sf::Event Event; while (App.GetEvent(Event)) { if (Event.Type == sf::Event::Closed) App.Close(); } sf::Shape tmpShape = sf::Shape::Circle(0, 0, 1, sf::Color::White); for (int i=0; i<200; i++) { tmpShape.SetPosition(i, i); App.Draw(tmpShape); App.Display(); Sleep(25); } } return EXIT_SUCCESS; }
Kann da jemand was erkennen, warum das so komisch ist? Oder ist mein code korrekt und es ist einfach so?
Hier ist mal ein screenshot:
(Link)
Ich bin über jeden Vorschlag dankbar.
Werbeanzeige