2d Map scrollen? (Wie in "Worms" oder "Soldat
Übersicht

shootermakerBetreff: 2d Map scrollen? (Wie in "Worms" oder "Soldat |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Hallo, hab ein problem mit den Scrollen einer 2d Map.
hier findet ihr den sourcecode: http://www.east-power-soft.de/...odes_worms hab ihn probiert wie folgt umzuändern: Code: [AUSKLAPPEN] width = 800 height = 600 Graphics width, height, 0, 2 sand = LoadImage("sand.png") grass = LoadImage("grass.png") stone = LoadImage("stone.png") hsand = ImageHeight( sand ) / 2 hgrass = ImageHeight( grass ) / 2 ;--> Erstellt Bild mit gleicher Größe wie Landschaftsbild und fülle mit "stone" Textur. grabber = CreateImage( width, height ) SetBuffer ImageBuffer( grabber ) TileBlock stone, 0, 0 ;--> Erstelle "land" ;land = CreateImage( width, height ) land = LoadImage("worms.bmp") ;--> Ermittle Referenzpixel SetBuffer ImageBuffer( land ) LockBuffer ImageBuffer( land ) WritePixelFast 0, 0, 0 black = ReadPixelFast( 0, 0 ) WritePixelFast 0, 0, $FF00FF pink = ReadPixelFast( 0, 0 ) UnlockBuffer ImageBuffer( land ) Local cam_x% = 32, cam_y% = 32 speed = 2 ;--> Beginne Schleife Repeat SeedRnd MilliSecs() If KeyDown(200) Then cam_y% = cam_y +speed If KeyDown(203) Then cam_x% = cam_x +speed If KeyDown(205) Then cam_x% = cam_x -speed If KeyDown(208) Then cam_y% = cam_y -speed SetBuffer ImageBuffer( land ) DrawBlock land, 0, 0 ;--> locke alle Buffer LockBuffer ImageBuffer( land ) LockBuffer ImageBuffer( sand ) LockBuffer ImageBuffer( grass ) LockBuffer ImageBuffer( grabber ) ;--> Landschaft mit "stone" Textur füllen For x = 0 To width - 1 transition = 0 For y = 0 To height - 1 ;--> Lies Pixel aus. pix = ReadPixelFast( x, y ) ;--> Wenn Schwarz Pixel, ersetze ihn durch "stone" Pixel If pix = black Then ;--> erster Schwarz Pixel nach Pink? Speichere Y-Position If transition = 0 Then ytop = y: transition = 1 WritePixelFast x, y, ReadPixelFast( x, y, ImageBuffer( grabber ) ) End If ;--> Pink Pixel oder Bilrdschirmkante? If pix = pink Or y = height - 1 Then ;--> Erster Pink Pixel nach schwarz? If transition = 1 Then ;--> Zeichne "sand" Textur an unteren Rand wenn NICHT unterer Bildschirmrand If y < height - 1 Then ysand = 0 For y1 = y - hsand * 2 To y - 1 If y1 > -1 And y1 < height Then psand = ReadPixelFast( xsand, ysand, ImageBuffer( sand ) ) If psand <> pink Then WritePixelFast x, y1, psand ysand = ysand + 1 End If Next xsand = xsand + 1: If xsand = ImageWidth( sand ) Then xsand = 0 End If ;--> Zeichne "grass" Textur an oberen Rand wenn NICHT oberer Bildschirmrand If ytop > 0 Then ygrass = 0 For y1 = ytop - hgrass To ytop + hgrass - 1 If y1 > -1 And y1 < height Then pgrass = ReadPixelFast( xgrass, ygrass, ImageBuffer( grass ) ) If pgrass <> pink Then WritePixelFast x, y1, pgrass ygrass = ygrass + 1 End If Next xgrass = xgrass + 1: If xgrass = ImageWidth( grass ) Then xgrass = 0 End If transition = 0 End If End If Next Next UnlockBuffer ImageBuffer( land ) UnlockBuffer ImageBuffer( sand ) UnlockBuffer ImageBuffer( grass ) UnlockBuffer ImageBuffer( grabber ) ;--> Maskieren wir nun das "land" MaskImage land, 0, 0, pink ;--> Erzeuge einen Hintergrund back = CreateImage( width, height ) SetBuffer ImageBuffer( back ) For y = 0 To height blue# = 255 / Float( height ) * y Color 0, 0, blue Rect 0, height-y, width, height-y, 1 Next For i=0 To 1 DrawBlock back, 0, 0 DrawImage land, 0+ cam_x%, 0+ cam_y% SetBuffer BackBuffer() Flip Next Until KeyHit(1) End leider ist die Scrollfunktion zu langsam. Ich bin echt am verzweifeln. hab schon das ganze Forum abgesucht aber nichts passendes gefunden. ![]() Hoffe auf eure Hilfe. Danke im voraus. EDIT: PROBLEM BEHOBEN, DANKE FÜR EURE HILFE! ![]() |
||
- Zuletzt bearbeitet von shootermaker am Mo, Dez 22, 2008 15:31, insgesamt einmal bearbeitet
![]() |
ozzi789 |
![]() Antworten mit Zitat ![]() |
---|---|---|
Such mal nach Tilemap(s) mit der Foren-suche
Auf Robsite hat es ein RPG Tutorial wo dies behandelt wird ![]() mfg |
||
0x2B || ! 0x2B
C# | C++13 | Java 7 | PHP 5 |
shootermaker |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
ozzi789 hat Folgendes geschrieben: Such mal nach Tilemap(s) mit der Foren-suche
Auf Robsite hat es ein RPG Tutorial wo dies behandelt wird ![]() mfg Hallo und danke für deine Antwort. Ich weiß was tilemaps sind. das Problem ist das ich das Bild nicht teilen möchte, sonder als ganzes scrollen. kann das funktionieren? ich meine das Bild is ja nicht sonderlich groß und würde dem Speicher nicht viel schaden, oder? ich glaub das problem liegt an den ReadPixel befehlen, aber wie kann ich das scrollen verbessern (performance)? |
||
![]() |
ozzi789 |
![]() Antworten mit Zitat ![]() |
---|---|---|
Klar funktioniert das, das Bild muss einfach genug gross sein ![]() zmb Du nimmst ein Fenster 800,600 und machst dein Level 1600,600 pixel gross nun um zu Scrollen kannst du einfach die X koordinate ändern. So oder so wieso willst du dein Level als Bild? Oo mfg[/code] |
||
0x2B || ! 0x2B
C# | C++13 | Java 7 | PHP 5 |
shootermaker |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Genau diese Methode wurde bei dem obigen Beispiel angewandt.
aber irgendetwas scheint bei dem Code nicht richtig zu laufen, da er das Bild viel zu langsam und träge scrollt (ich meine die fps zahl geht gegen 0). |
||
![]() |
Eingeproggt |
![]() Antworten mit Zitat ![]() |
---|---|---|
Einrfach mal die Map in ein eigenes Bild speichern (CreateImage![]() ![]() |
||
Gewinner des BCC 18, 33 und 65 sowie MiniBCC 9 |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group