[B2D] Mehrere Tileset's und mehrere Layer
Übersicht

![]() |
N0XBetreff: [B2D] Mehrere Tileset's und mehrere Layer |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hallo!
Ich habe mir einen Mapeditor selber gebaut und habe versucht mehrere Ebenen zu verwenden mit verschiedenen Tileset's. Es gibt bei mir einen starken Performance-Verlust wenn ich 2 Ebenen mit jeweils 200x200 Tiles verwende. Wie kann ich das optimieren? Da ich nicht weiß' wo mein Fehler liegen könnte hier der gesamte Code: [AUSKLAPPEN] Graphics 1024,768,32,1
SetBuffer BackBuffer() Global x,y,tile=0,scroll_x,scroll_y,set=1 Global tileset = LoadAnimImage("gfx\tileset.png",16,16,0,4) Global tileset2 = LoadAnimImage("gfx\tileset2.png",16,16,0,2):MaskImage tileset2,255,0,255 maus = LoadImage("gfx\maus.bmp") Dim map(200,200) Dim item(20,20) MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 While Not KeyHit(1) Cls mx=MouseX() my=MouseY() For x=0 To 200 For y=0 To 200 DrawBlock tileset,x*16-scroll_x,y*16-scroll_y,map(x,y) Next Next For x=0 To 20 For y=0 To 20 DrawImage tileset2,x*16-scroll_x,y*16-scroll_y,item(x,y) Next Next If KeyHit(57) Then tile=tile+1 If tile>=3 Then tile=3 If tile<=0 Then tile=0 If KeyHit(31) Then save() If KeyHit(38) Then load() If MouseX()<=0 Then scroll_x=scroll_x-4 If MouseX()>=GraphicsWidth()-5 Then scroll_x=scroll_x+4 If MouseY()<=0 Then scroll_y=scroll_y-4 If MouseY()>=GraphicsHeight()-5 Then scroll_y=scroll_y+4 If KeyHit(27) Then set=set+1 If KeyHit(53) Then set=set-1 If set>=2 Then set=2 If set<=1 Then set=1 If MouseDown(1) Then mapx=(mx)/16 mapy=(my)/16 If set=1 Then map(mapx+scroll_x/16,mapy+scroll_y/16)=tile EndIf If set=2 Then item(mapx+scroll_x/16,mapy+scroll_y/16)=1 EndIf EndIf If MouseDown(2) Then mapx=(mx)/16 mapy=(my)/16 map(mapx+scroll_x/16,mapy+scroll_y/16)=0 EndIf DrawImage maus,mx,my Flip Wend End Function save() karte$ = WriteFile("map1.map") For x = 0 To 200 For y = 0 To 200 WriteLine(karte$,tile) WriteInt(karte$,map(x,y)) Next Next For x=0 To 20 For y=0 To 20 WriteInt(karte$,item(x,y)) Next Next CloseFile(karte$) End Function Function load() karte$ = ReadFile("map1.map") For x = 0 To 200 For y = 0 To 200 tile = ReadLine(karte$) map(x,y) = ReadInt(karte$) Next Next For x=0 To 20 For y=0 To 20 item(x,y) = ReadInt(karte$) Next Next CloseFile(karte$) End Function Mfg, N0X |
||
Projekte: |Tibario| http://www.blitzforum.de/worklogs/325/ | 5% |
![]() |
The_Nici |
![]() Antworten mit Zitat ![]() |
---|---|---|
Zeichne nur die Tiles die man sieht. | ||
![]() |
N0X |
![]() Antworten mit Zitat ![]() |
---|---|---|
Gibt es dazu einen Befehl, oder muss ich mir das selber schreiben?
//EDIT Ok Viewport ist der Befehl. Trotzdem noch ziemlich langsam. Warum? |
||
Projekte: |Tibario| http://www.blitzforum.de/worklogs/325/ | 5% |
![]() |
Eingeproggt |
![]() Antworten mit Zitat ![]() |
---|---|---|
Code: [AUSKLAPPEN] For x=0 To 200
For y=0 To 200 DrawBlock tileset,x*16-scroll_x,y*16-scroll_y,map(x,y) Next Next Das in Viewport zu stecken bringt nichts. Der Grund warum das so langsam ist, ist dass du da immer noch 201*201=40401 Bilder zeichnest.... Auch wenn sie außerhalb des sichtbaren Bereichs liegen... Du musst es abfragen, in etwa so: Code: [AUSKLAPPEN] For x=0 To 200
For y=0 To 200 If x*16>scroll_x and x*16<scroll_x+GraphicsWidth() and y*16>scroll_y and y*16<scroll_y+GraphicsHeight() Then DrawBlock tileset,x*16-scroll_x,y*16-scroll_y,map(x,y) Endif Next Next Achtung: Nur ein Vorschlag, ich kann das ja nicht testen und wenn dir am Rand was fehlt oder wenn dein Scrollsystem überhaupt anders is oder deine Variablen nicht in Pixel sondern in Tiles angegeben sind dann musst du das selber berücksichtigen. EDIT: GraphicsWidth() und GraphicsHeight() vorher in Variablen speichern, damit die Sache beschleunigt wird! mfG, Christoph. EDIT2: Stimmt *an-den-kopf-klatsch* |
||
Gewinner des BCC 18, 33 und 65 sowie MiniBCC 9 |
- Zuletzt bearbeitet von Eingeproggt am Sa, Mai 09, 2009 20:08, insgesamt einmal bearbeitet
![]() |
The_Nici |
![]() Antworten mit Zitat ![]() |
---|---|---|
Eingeproggt, kann man auch einfacher machen:
Code aus meinem Editor: Code: [AUSKLAPPEN] For my = 0 To map_w - scroll_y For mx = 0 To map_h - scroll_x DrawImage usedtileset, mx * 32, my * 32, map(mx + scroll_x, my + scroll_y) Next Next Wie man erkennt zwacke ich das schon in der For-Schleife ab. |
||
![]() |
N0X |
![]() Antworten mit Zitat ![]() |
---|---|---|
Das wollte ich auch nicht!
Ich wollte lediglich einen Lösungsansatz! Also, vielen Dank, funktioniert wunderbar! Mfg, N0X |
||
Projekte: |Tibario| http://www.blitzforum.de/worklogs/325/ | 5% |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group