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 |
retval = HeapFree(_crtheap, 0, pBlock); if (retval == 0) { errno = _get_errno_from_oserr(GetLastError()); } |
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 134 135 136 |
#include <iostream> #include <SFML/Graphics.hpp> #include <SFML/Audio.hpp> int main() { /////Sprite///// enum direction {Down, Left, Right, Up}; sf::Vector2i source(1, Down); sf::Vector2i gsource(1, Down); sf::Texture tplayer; tplayer.loadFromFile("Sprites/player.png"); sf::Sprite player(tplayer); player.setPosition(360,250); player.setOrigin(16,16); sf::Texture tghost; tghost.loadFromFile("Sprites/Ghost.png"); sf::Sprite ghost(tghost); ghost.setPosition(417,15); sf::Texture tbackground; tbackground.loadFromFile("Sprites/Town.png"); sf::Sprite background(tbackground); background.setScale(2.087,1.873); background.setPosition(400,300); background.setOrigin((tbackground.getSize().x / 2),(tbackground.getSize().y / 2)); /////Music and Sound///// sf::Music backgroundmusic; backgroundmusic.openFromFile("Music and Sound/Pokemon_Theme.ogg"); backgroundmusic.setVolume(50); backgroundmusic.setLoop(true); backgroundmusic.play(); //Zeit sf::Clock clock; sf::Time time = clock.restart(); sf::Clock animationclockplayer; sf::Time animationtimeplayer = animationclockplayer.restart(); sf::Time animationtime2 = sf::milliseconds(200); sf::Clock animationclockghost; sf::Time animationtimeghost = animationclockghost.restart(); sf::Time animationtime3 = sf::milliseconds(100); ////////////////////////////////Runtime-Loop//////////////////////////////////// sf::RenderWindow Window(sf::VideoMode(800,600), "Pokémon 2.0", sf::Style::Close); while(Window.isOpen()) { //time animationtimeplayer = animationclockplayer.getElapsedTime(); animationtimeghost = animationclockghost.getElapsedTime(); time = clock.getElapsedTime(); //Event-Loop sf::Event Event; while (Window.pollEvent(Event)) { switch (Event.type) { case sf::Event::Closed: Window.close(); break; case sf::Event::KeyPressed: if (Event.key.code == sf::Keyboard::Escape) Window.close(); break; } } /////Controls player///// if (sf::Keyboard::isKeyPressed) clock.restart(); if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { source.y = Down; player.move(0,0.1 * time.asMilliseconds()); } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { source.y = Left; player.move(-0.1 * time.asMilliseconds(),0); } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { source.y = Right; player.move(0.1 * time.asMilliseconds(),0); } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { source.y = Up; player.move(0,-0.1 * time.asMilliseconds()); } /////Kollisionen///// //outline if (player.getPosition().y < 46) //down player.move(0,0.1 * time.asMilliseconds()); else if (player.getPosition().x > 725) //left player.move(-0.1 * time.asMilliseconds(),0); else if (player.getPosition().x < 75) //right player.move(0.1 * time.asMilliseconds(),0); else if (player.getPosition().y > 555) //up player.move(0,-0.1 * time.asMilliseconds()); //Animation player if (animationtimeplayer > animationtime2) { source.x++; animationclockplayer.restart(); } if(source.x * 32 >= tplayer.getSize().x) source.x = 0; //Animation ghost if (animationtimeghost > animationtime3) { gsource.x++; animationclockghost.restart(); if(gsource.x * 32 >= tghost.getSize().x) gsource.x = 0; } /////Display///// player.setTextureRect(sf::IntRect(source.x * 32, source.y * 32, 32, 32)); ghost.setTextureRect(sf::IntRect(gsource.x * 32, gsource.y * 32, 32, 32)); Window.clear(); Window.draw(background); Window.draw(ghost); Window.draw(player); Window.display(); } return 0; } |
C-/C++-Quelltext |
|
1 |
tplayer.loadFromFile("Sprites/player.png");
|
C-/C++-Quelltext |
|
1 2 3 4 |
if( ! tplayer.loadFromFile("Sprites/player.png")) // wenn nicht geladen werden kann { return 1; // Fehler } |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Könntest du mir das bitte genauer erklären? Wo schaue ich das nach?Und was sagt der Stacktrace woher die Exception kommt? Also aus welchen Klassen und Methoden?
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Werbeanzeige