; German forum: http://www.purebasic.fr/german/viewtopic.php?t=10196&postdays=0&postorder=asc&start=20 ; Author: PMV (code updated with a working example by Andre) ; Date: 07. October 2006 ; OS: Windows ; Demo: Yes ; Little procedure, which loads a set of map tiles and create a ; sprite with the scene of it. ; Hier hab ich ne kleine Prozedur erstellt, die ein Sprite mit der ; entsprechenden Szene zurück gibt. Damit sind Diashows mit größeren ; Schnick-Schnack kein problem. (Stichwort "Überblenden" als Beispiel) ; Zur Veranschaulichung hab ich zusätzlich noch ein kleines Programm ; geschrieben, das diese Prozedur nutzt, um eine Diashow in der ; einfachsten Form zu zeigen. Die Größe des Fensters kann beliebig ; verändert werden. ;die Größe des Fensters kann nach belieben verändert werden (darf nicht größer als die Map sein!) #WindowWidth = 400 ;-PB-Bug unter ca. 120 gibts einen Rand im Screen o_O #WindowHeight = 200 ; ---------------------------------------------------------------------- ; ---------------------------------------------------------------------- ;ab hier beginnt das Programm selber, Änderungen auf eigene Gefahr *lol* #MapWidth = 10 ; number of tiles #MapHeight = 3 ; number of tiles #AlleTiles = #MapWidth * #MapHeight #TileWidth = 64 ; width of a tile in pixel #TileHeight = 64 ; height of a tile in pixel Global Dim Map(#MapWidth - 1, #MapHeight - 1) ;Gibt ein Image mit der übergebenen Szene zurück Procedure CreateMap(X, Y, Width, Height) ; all parameters are given in pixel ; X and Y are the start position of the map (top-left corner) ; Width and Height are the map size starting at X, Y ; the needed tiles are calculated automatically FirstTileX = X / #TileWidth FirstTileY = Y / #TileHeight LastTileX = FirstTileX + (Width / #TileWidth) LastTileY = FirstTileY + (Height / #TileHeight) Image = CreateImage(#PB_Any, Width, Height, #PB_Image_DisplayFormat) If Not Image : ProcedureReturn #False : EndIf StartDrawing(ImageOutput(Image)) For x = FirstTileX To LastTileX For y = FirstTileY To LastTileY Debug "x= " + Str(x) + " y = " + Str(y) Debug Map(x+1, y+1) CallDebugger ;DrawImage(ImageID(Map(x, y)), x * #TileWidth, y * #TileHeight) Next Next ; For DisplayX = X % TileWidth To Width-1 Step #TileWidth ; For DisplayY = Y % TileHeight To Height-1 Step #TileHeight ; DrawImage(ImageID(Map(TileX, TileY)), DisplayX, DisplayY) ; TileY + 1 ; Next ; TileY = Abs(Int(Y / #TileHeight)) ; TileX + 1 ; Next StopDrawing() ProcedureReturn Image EndProcedure ; ------------------------------------------------------------- MainWindow = OpenWindow(#PB_Any, 0, 0, #WindowWidth, #WindowHeight, "Map & Tiles", #PB_Window_Invisible | #PB_Window_SystemMenu | #PB_Window_ScreenCentered) CreateGadgetList(WindowID(MainWindow)) PosX = Random(#TileWidth * #MapWidth - #WindowWidth) PosY = Random(#TileHeight * #MapHeight - #WindowHeight) Szene = CreateMap(0, 0, #WindowWidth, #WindowHeight) ImageGad = ImageGadget(#PB_Any, 0, 0, #MapWidth*#TileWidth, #MapHeight*#TileHeight, Szene) ;ScrollAreaGadget(#PB_Any, 0, 0, #WindowWidth, #WindowHeight, #MapWidth*#TileWidth, #MapHeight*#TileHeight, 10) ProgressWindow = OpenWindow(#PB_Any, 0, 0, 310, 30, "Loading...", #PB_Window_BorderLess |#PB_Window_ScreenCentered) CreateGadgetList(WindowID(ProgressWindow)) ContainerGadget(#PB_Any, -1, -1, 310, 30, #PB_Container_Raised) Progress = ProgressBarGadget(#PB_Any, 3, 3, 300, 20, 0, #AlleTiles) ; Laden der Grafiken x = 0 y = 0 For i = 0 To #AlleTiles-1 While WindowEvent() : Wend Map(x, y) = LoadImage(#PB_Any, "..\..\Graphics\Gfx\TileSet\" + RSet(Str(i+1), 3, "0") + ".bmp") If Not Map(X, Y) MessageRequester("Error", "Can't load tile " + RSet(Str(i+1), 3, "0") + "!") End EndIf x + 1 If x >= #MapWidth : y + 1 : x = 0 : EndIf SetGadgetState(Progress, i + 1) Next CloseWindow(ProgressWindow) HideWindow(MainWindow, #False) ; StartDrawing(ImageOutput(Szene)) ; DrawImage(Map(1,1), 0, 0) ; StopDrawing() ;SetGadgetState(Image, ImageID(Szene)) ;Hauptschleife Time = Random(3000) + 1000 ;zufällige Anzeigedauer pro Bild Timer = ElapsedMilliseconds() - Time Repeat If Timer + Time <= ElapsedMilliseconds() Timer = ElapsedMilliseconds() Time = 1000 ;If Szene : FreeSprite(Szene) : EndIf PosX = Random(#TileWidth * #MapWidth - #WindowWidth) PosY = Random(#TileHeight * #MapHeight - #WindowHeight) ;Szene = CreateScene(PosX, PosY, #WindowWidth, #WindowHeight) ;DisplaySprite(Szene, 0, 0) ;FlipBuffers() EndIf Until WaitWindowEvent(100) = #PB_Event_CloseWindow ; IDE Options = PureBasic v4.02 (Windows - x86) ; Folding = - ; EnableXP