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 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 |
//////////////////////Der Code aus der MainLoop Input.Update(); if (Input.GetRawKeyboard().IsKeyPressed("UP")) { point_of_origin.y -= 50 * d_time; } if (Input.GetRawKeyboard().IsKeyPressed("DOWN")) point_of_origin.y += 50 * d_time; if (Input.GetRawKeyboard().IsKeyPressed("LEFT")) point_of_origin.x -= 50 * d_time; if (Input.GetRawKeyboard().IsKeyPressed("RIGHT")) point_of_origin.x += 50 * d_time; //////////Die isKeyPressed Methode, die in der MainLoop aufgerufen wird const bool KeyboardInput::IsKeyPressed(const std::string name) const { for (auto key : Keytable.GetTable()) { if (key.GetName() == name) return key.IsPressed(); } } //////////////Die IsPressed Methode, die eben aufgerufen wurde bool IsPressed() const { return PressedThisFrame; } ///////// Update des Keys(wird bei Input.Update() ausgeführt): bool KeyboardKey::Update() { PressedLastFrame = PressedThisFrame; if (sf::Keyboard::isKeyPressed(Sf_Key)) PressedThisFrame = true; else PressedThisFrame = false; return true; } |
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 |
/////////////////////////////////////////////////////Das Hier alles ist dann der "Key" class InputKey { public: InputKey(std::string name) //Standardconstructor : Name{ name }, PressedLastFrame{ false }, PressedThisFrame{ false } {} //virtual ~InputKey(); //Memberfunctions bool JustGotPressed() const { return (PressedThisFrame && !PressedLastFrame); } bool IsPressed() const { return PressedThisFrame; } bool WasReleased() const { return (PressedLastFrame && !PressedThisFrame); } const std::string GetName() const { return Name; } virtual void Update() = 0; protected: bool PressedThisFrame; bool PressedLastFrame; std::string Name; }; //KEYBOARD class KeyboardKey : public InputKey { public: KeyboardKey(std::string name, sf::Keyboard::Key key) : InputKey( name ), Sf_Key{ key } {}; //virtual ~KeyboardKey(); virtual void Update() override; bool operator == (const KeyboardKey key) const; private: sf::Keyboard::Key Sf_Key; }; |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »ERROR« (12.05.2014, 00:14)
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 |
//////////Die isKeyPressed Methode, die in der MainLoop aufgerufen wird const bool KeyboardInput::IsKeyPressed(const std::string name) const { for (auto &key : Keytable.GetTable())/////// Hier das '&' { if (key.GetName() == name) return key.IsPressed(); } } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »ERROR« (12.05.2014, 16:46)
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Werbeanzeige