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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
#ifndef C_EASYANIMATION_HPP #define C_EASYANIMATION_HPP #include <SFML/Graphics.hpp> #include <iostream> #include <string> class EasyAnimation { private: sf::Clock m_AniClock; // Misst die Zeit zwischen den Frames. sf::Time m_AniTime; // Nimmt vergangene Zeit zwischen den Frames auf. sf::Time m_AniSpeed; // Nimmt die Geschwindigkeit in Sekunden auf, in der die Animation ablaufen soll. int m_Pictures_per_Line; // Sagt aus wie viele Bilder die Animation pro Reihe hat. int m_Lines; // Sagt aus wie viele Reihen die Animation hat. int m_PictureStop; // Hier kann angegeben werden an welchem Bild der Reihe gestoppt werden soll. int m_LineStop; // Hier kann angegeben werden in welcher Reihe die Animation anhalten soll. int m_Left; int m_Top; int m_Wight; int m_Hight; std::string m_TexturName; // Enthält den Pfad zur Textur. sf::Texture m_Texture; // Zur aufnahme der Textur; sf::Sprite m_Sprite; // Nimmt die geladene Textur auf. bool m_AniRunning; // Sagt aus ob die Animation laufen soll oder nicht. public: // Konstruktor EasyAnimation (std::string & s , int Wight, int Hight, int Pictures, int Lines, sf::Time & Time); // Funktion zum durchlaufen des gesamten Sprites. void RunFullAnimation (); // Funktion zum durchlaufen einer gewünschten Reihe des Sprites. void RunLine (int Line); // Funktion zum sofortigen anhalten der Animation. void StopAnimation (); // Funktion um die Animation zu stoppen und stadtdessen ein gewünschtes Bild des Sprites anzuzeigen. void StopAnimation_on_Rect (int Picture, int Line); // Funktion zum zeichnen der Animation void DrawAnimation (sf::RenderWindow & window); // Funktion um die Position des Sprites zu setzen. void SetAniPosition (int Wight, int Hight); }; #endif |
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
#include "Animation.hpp" #include <SFML/Graphics.hpp> #include <iostream> #include <string> // Konstruktor EasyAnimation::EasyAnimation (std::string & s , int Wight, int Hight, int Pictures, int Lines, sf::Time & Time) { m_TexturName = s; if (!m_Texture.loadFromFile (s) ) { std::cout << "Could not load the Texture"; } m_Sprite.setTexture (m_Texture); m_Wight = Wight; m_Hight = Hight; m_Left = 0; m_Top = 0; m_Pictures_per_Line = Pictures; m_Lines = Lines; m_PictureStop = 0; m_LineStop = 0; m_AniSpeed = Time; } // Funktion zum durchlaufen des gesamten Sprites. void EasyAnimation::RunFullAnimation () { m_AniRunning = true; m_Left = 0; m_Top = 0; if (m_AniRunning = true) { m_Sprite.setTextureRect (sf::IntRect ( m_Left * m_Wight, m_Top *m_Hight, m_Wight, m_Hight ) ); m_AniTime = m_AniClock.getElapsedTime (); if (m_AniTime >= m_AniSpeed ) { m_Left++; m_AniClock.restart (); if (m_Left >= m_Pictures_per_Line ) { m_Left = 0; m_Top ++; m_AniClock.restart (); if (m_Top >= m_Lines ) { m_Left = 0; m_Top = 0; } } } } } // Funktion zum durchlaufen einer gewünschten Reihe des Sprites. void EasyAnimation::RunLine (int Line) { m_AniRunning = true; m_Left = 0; m_Top = Line; if (m_AniRunning = true) { m_Sprite.setTextureRect (sf::IntRect ( m_Left * m_Wight, m_Top *m_Hight, m_Wight, m_Hight ) ); m_AniTime = m_AniClock.getElapsedTime (); if (m_AniTime >= m_AniSpeed ) { m_Left++; m_AniClock.restart (); } if (m_Left >= m_Pictures_per_Line ) { m_Left = 0; m_AniClock.restart (); } } } // Funktion zum sofortigen anhalten der Animation. void EasyAnimation::StopAnimation () { m_AniRunning = false; } // Funktion um die Animation zu stoppen und stadtdessen ein gewünschtes Bild des Sprites anzuzeigen. void EasyAnimation::StopAnimation_on_Rect (int Picture, int Line) { m_AniRunning = false; m_Sprite.setTextureRect (sf::IntRect ( Picture * m_Wight, Line *m_Hight, m_Wight, m_Hight ) ); } // Funktion zum zeichnen der Animation void EasyAnimation::DrawAnimation (sf::RenderWindow & window) { window.draw (m_Sprite); } // Funktion um die Position des Sprites zu setzen. void EasyAnimation::SetAniPosition (int Wight, int Hight) { m_Sprite.setPosition (Wight, Hight); } |
stadtdessen sagt er er erwarte (const Name der Klasse &) .
Zitat
Eine Fehlermeldung kommt erst gar nicht zustande da der Aufruf des Konstruktors ja schon fehlschlägt.
Zitat
wenn ich versuche den Konstruktor der Klasse in meiner main.cpp aufzurufen
C-/C++-Quelltext |
|
1 |
EasyAnimation Animation_A (String_A, 32, 32, 3, 4, Time_A); |
Alter Hase
Beruf: Softwareentwickler (aktuell Web/Node); Freiberuflicher Google Proxy
Werbeanzeige