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#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Surface Create(ushort width, ushort height, ubyte deepth) { assert(deepth >= 8 && deepth <= 32); this.Free(); this._surface = SDL_Check(SDL_CreateRGBSurface( 0, width, height, deepth, 0, 0, 0, 0 )); return this; } |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
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 |
/** * */ void Load(string file = "") { if (file.length > 0) { this._tmr.Read(file); } // Tileset Objekt erstellen Surface tileset = new Surface(); const string tileset_file = strip(this._tmr.GetTilesetFile()); // Tileset laden tileset.LoadFromFile(tileset_file); const ushort tw = this._tmr.GetTileWidth(); const ushort th = this._tmr.GetTileHeight(); const ushort tiles_each_line = cast(ushort)(tileset.Width / tw); Surface[ushort] tiles; ushort count = 0; Rect tile_rect = new Rect(0, 0, tw, th); // Die Positionen der Tiles innerhalb des Tiles errechnen (mit den Daten aus der .tmx Datei) foreach (const Tile t; this._tmr.GetTiles()) { if (t.Gid !in tiles) { const ushort[2] pos = CalcPos(t.Gid, tiles_each_line, tw, th); // Position des Rect's setzen tile_rect.SetPosition(pos[0], pos[1]); // Subsurface speichern, mit seiner ID tiles[t.Gid] = tileset.SubSurface(tile_rect); ++count; } } // Größe des neuen Tileset errechnen ushort size = 2; while (size < count) { size *= 2; } if (size > 2) { size = cast(ushort) floor(sqrt(cast(float) size)); } writefln("count: %d, size: %d", count, size); // Größe mal Tile Breite und Höhe const ushort w = cast(ushort)(size * tw); // (count > 2 ? size : count) const ushort h = cast(ushort)(size * th); writefln("w: %d, h: %d", w, h); // Neues Tileset erstellen Surface new_tileset = new Surface(); new_tileset.Create(w, h, 32); ushort line, column; //Rect clip = new Rect(0, 0, tw, th); tile_rect.SetPosition(0, 0); this._vtable.clear(); // Tileset befüllen mit den notwendigen Tiles foreach (ushort gid, Surface tile; tiles) { new_tileset.Blit(tile, tile_rect); this._vtable[gid] = [tile_rect.x, tile_rect.y]; column++; if (column >= size) { column = 0; line++; } const ushort rx = cast(ushort)(column * tile_rect.Width); const ushort ry = cast(ushort)(line * tile_rect.Height); //writefln("rx: %d, ry: %d", rx, ry); tile_rect.SetPosition(rx, ry); } /* new_tileset.SetAlphaMod(0); new_tileset.SetBlendMode(Surface.BlendMode.Multiply); */ // gucken was ich da fabriziert habe new_tileset.SaveToFile("img/Tiled/new_tileset.png"); Texture.Format fmt; if (new_tileset.IsMask(Surface.Mask.Red, 0x000000FF)) { fmt = Texture.Format.None; } else { fmt = (new_tileset.CountBytes() == 4) ? Texture.Format.BGRA : Texture.Format.BGR; } //writefln("CountBits: %d", new_tileset.CountBits()); // 32 this._tex.LoadFromPixels(new_tileset.GetPixels(), w, h, new_tileset.CountBits(), fmt); //this._tex.CreateMaskFromColor(Color.Black.Modify(Color.Spectrum.Alpha, 0), 255); this._need_update = true; } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Architekt« (25.05.2012, 14:12)
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »BlueCobold« (25.05.2012, 15:02)
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Surface Create(ushort width, ushort height, ubyte depth) { assert(depth >= 8 && depth <= 32); this.Free(); this._surface = SDL_Check(SDL_CreateRGBSurface( 0, width, height, depth, 0, 0, 0, 0 )); return this; } |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Werbeanzeige