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
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
#include <iostream> #include "windows.h" #include <SFML\Graphics.hpp> using namespace std; int main() { sf::Clock(); //Sprite sf::Image square1; square1.loadFromFile ("square.bmp"); sf::Sprite player1(square1)/*1. Problem bei square1*/; player1.setOrigin(25,25); player1.setPosition(400,300); //Laufzeitvariable sf::Event Event; bool running = true; //Fenster sf::RenderWindow Fenster(sf::VideoMode(800,600,32),"Spiel"); sf::Keyboard Input = Fenster.getPosition()/*2. Problem bei Fenster*/; //Zeit sf::Clock Uhr; sf::Time Zeit = Uhr.getElapsedTime(); while (running == true) { while (Fenster.pollEvent(Event)) { if((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape)) { Fenster.close(); running = false; } } if (Input.isKeyPressed(sf::Keyboard::W)) { player1.move(0,(-1 * Zeit.asMilliseconds())); Uhr.restart(); } if (Input.isKeyPressed(sf::Keyboard::A)) { player1.move((1 * Zeit.asMilliseconds()), 0)); Uhr.restart(); } if (Input.isKeyPressed(sf::Keyboard::S)) { player1.move(0,(1 * Zeit.asMilliseconds())); Uhr.restart(); } if (Input.isKeyPressed(sf::Keyboard::D)) { player1.move((-1 * Zeit.asMilliseconds()), 0); Uhr.restart(); } Fenster.clear(sf::Color::Black); Fenster.draw(player1); Fenster.display(); //3. Problem bei Fenster } return 0; } |
Bitte noch eine Sache, ich finde, es lohnt nicht, dafür einen neuen Thread zu erstellen:
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 #include #include "windows.h" #include using namespace std; int main() { sf::Clock(); //Wieso Brudii? //Sprite sf::Image square1; square1.loadFromFile ("square.bmp"); sf::Sprite player1(square1)/*1. Problem bei square1*/; //Mach sf::Texture *blabla* -> Auf Adresse verweisen, also &square1 player1.setOrigin(25,25); //SetSize fehlt?? Dürfte nur 0x0 Pixel groß sein player1.setPosition(400,300); //Laufzeitvariable sf::Event Event; bool running = true; //Fenster sf::RenderWindow Fenster(sf::VideoMode(800,600,32),"Spiel"); sf::Keyboard Input = Fenster.getPosition()/*2. Problem bei Fenster*/; //Welche Posis?? Du fragst nur Tasten ab //Zeit sf::Clock Uhr; sf::Time Zeit = Uhr.getElapsedTime(); //1x Aufrufen?? Das muss ständig passieren, die FPS kann sich im Spielverlauf immer ändern while (running == true) //Mach lieber mit window.isOpen() muss aber nicht { while (Fenster.pollEvent(Event)) { if((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape)) //Weißt bescheid.. { Fenster.close(); //Naja.. *hust* running = false; } } if (Input.isKeyPressed(sf::Keyboard::W)) { player1.move(0,(-1 * Zeit.asMilliseconds())); //asMilliseconds wird ganz schön schnell.. =D Uhr.restart(); //Das bringt dir gar nichts, wenn du den Wert nicht in einer sf::Time Instanz speicherst. } if (Input.isKeyPressed(sf::Keyboard::A)) { player1.move((1 * Zeit.asMilliseconds()), 0)); Uhr.restart(); } if (Input.isKeyPressed(sf::Keyboard::S)) { player1.move(0,(1 * Zeit.asMilliseconds())); Uhr.restart(); } if (Input.isKeyPressed(sf::Keyboard::D)) { player1.move((-1 * Zeit.asMilliseconds()), 0); Uhr.restart(); } Fenster.clear(sf::Color::Black); //Der cleart automatisch auf Schwarz, brauchst keinen Parameter Fenster.draw(player1); Fenster.display(); //3. Problem bei Fenster } return 0; }
Die Fehler sind eingetragen, es sind wahrscheinlich Kleinigkeiten, es lohnt nicht, dafür einen neuen Thread zu erstellen..</iostream>
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »SwatzZ« (06.05.2013, 20:26)
Alter Hase
Beruf: Softwareentwickler (aktuell Web/Node); Freiberuflicher Google Proxy
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
#include <iostream> #include "windows.h" #include <SFML\Graphics.hpp> using namespace std; int main() { //Sprite sf::Texture square1; square1.loadFromFile ("square.jpg"); sf::Sprite player1; player1.setTexture(square1); player1.setOrigin(25,25); player1.setPosition(400,300); //Laufzeitvariable sf::Event Event; bool running = true; //Fenster sf::RenderWindow Fenster(sf::VideoMode(800,600,32),"Spiel"); sf::Keyboard Input; //Zeit sf::Clock Uhr; sf::Time Zeit = Uhr.getElapsedTime(); //Laufzeitschleife und Steuerung while (running == true) { while (Fenster.pollEvent(Event)) { if((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape)) { Fenster.close(); running = false; } } if (Input.isKeyPressed(sf::Keyboard::W)) { player1.move(0,(-1 * Zeit.asMilliseconds())); Uhr.restart(); } if (Input.isKeyPressed(sf::Keyboard::A)) { player1.move((1 * Zeit.asMilliseconds()), 0); Uhr.restart(); } if (Input.isKeyPressed(sf::Keyboard::S)) { player1.move(0,(1 * Zeit.asMilliseconds())); Uhr.restart(); } if (Input.isKeyPressed(sf::Keyboard::D)) { player1.move((-1 * Zeit.asMilliseconds()), 0); Uhr.restart(); } Fenster.clear(sf::Color::Black); Fenster.draw(player1); Fenster.display(); } return 0; } |
Werbeanzeige