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 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 |
Framework.h #include <WinAllegro.h> #include <string> #include "Singleton.h" #include "Sprite.h" using namespace std; #define g_pFramework Framework::Get() class Framework : public TSingleton<Framework> { public: bool Init(int screenwidth, int screenheight, int depth, bool fullscreen); }; #endif Framework.cpp #include "Framework.h" bool Framework::Init(int screenwidth, int screenheight, int depth, bool fullscreen) { allegro_init(); install_keyboard(); set_color_depth(depth); if(fullscreen == true) { if(set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, screenwidth, screenheight, 0, 0) < 0) { allegro_message("Unable to set Graphic Mode"); return (false); } } else if(fullscreen == true) { if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, screenwidth, screenheight,0,0) < 0) { allegro_message("Unable to set Graphic Mode"); return (false); } } return (true); } Sprite.h #ifndef SPRITE_H #define SPRITE_H #include "Framework.h" class Sprite { public: Sprite(); void LoadGraphic(const std::string Filename); void SetPos(float x, float y); void Render(); private: BITMAP *Graphic; int x; int y; int w; int h; }; #endif Sprite.cpp #include "Sprite.h" Sprite::Sprite() { this->x = 0; this->y = 0; } void Sprite::LoadGraphic(const std::string Filename) { Graphic = load_bitmap(Filename.c_str(), NULL); if(Graphic == 0) { allegro_message("Unable to Load Graphic"); exit(1); } if(Graphic) { this->w = Graphic->w; this->h = Graphic->h; } } void Sprite::SetPos(float x, float y) { this->x = static_cast<int>(x); this->y = static_cast<int>(y); } void Sprite::Render() { acquire_screen(); clear(screen); blit(Graphic, screen, 0, 0, this->x, this->y, this->w, this->h); release_screen(); } main.cpp #include "Framework.h" int main(int argv, char **argc) { if(g_pFramework->Init(640, 320, 16, false) == false) allegro_message("Unable to Initialize Allegro"); Sprite *test = new Sprite; test->LoadGraphic("allegro.tga"); test->SetPos(100,200); test->Render(); while (!keypressed()); g_pFramework->Del(); return 0; } END_OF_MAIN() |
Zitat von »"amida maru"«
vs2005 wirft mir ein debugger hinterher. und fragt ob ich ne neue instanz von vs2005 will. an SetPos liegts sicher net... die zwei float werte waren im heiko kalista buch auch. es liegt am initalisieren weil wenn ich per hand an initialisiere dann funktioniert alles. er sagt mir keinen genauen fehler..
Zitat von »"amida maru"«
screen ist die globale variable wo man immer drauf blittet.
und wie man sieht wird alles initialisiert:
init_allegro()
install_keyboard();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_WINDOWED,800,600,0,0);
Werbeanzeige