Hilfe beim "Point" Befehl

Anfängerfragen zum Programmieren mit PureBasic.
NathanielBlack
Beiträge: 63
Registriert: 25.12.2009 18:48

Hilfe beim "Point" Befehl

Beitrag von NathanielBlack »

Hi!

Wäre lieb wenn ihr mir sagen könntet, wieso hier der Point Befehl nicht funktioniert (Fehler = Outside the drawing area)

Code: Alles auswählen



InitSprite()
InitMouse()
InitKeyboard()

ExamineDesktops()

OpenScreen(DesktopWidth(0),DesktopHeight(0),DesktopDepth(0),"Niklas Upmann",#PB_Screen_SmartSynchronization,DesktopFrequency(0))

Global mx,my,ScrollX,ScrollY

UsePNGImageDecoder()

Structure Karte
     typ.s
     besetzt.b
EndStructure

Global Dim Karte.Karte(900,900)

Procedure Load_Map_Tiles()
     tsprite = LoadSprite(#PB_Any,"terrain.png")
     DisplaySprite(tsprite,0,0)
     StartDrawing(ScreenOutput())
  
     width = SpriteWidth(tsprite)
     height = SpriteHeight(tsprite)
     If width > 800 Or height > 800
          End
     EndIf
     
          For x = 0 To width
               For y = 0 To height
                    Karte(x,y)
                    farbe = Point(x,y)
                    If Green(farbe) = 94 And Red(farbe) = 0 And Blue(farbe) = 0
                         Karte(x,y)\typ = "1"
                    ElseIf Green(farbe) = 0 And Red(farbe) = 0 And Blue(farbe) = 197
                         Karte(x,y)\typ = "0"
                    EndIf
                    
               Next
          Next
          
     StopDrawing()
     
EndProcedure

Load_Map_Tiles()



Repeat
     
     ExamineMouse()
     ExamineKeyboard()
     mx = MouseX()
     my = MouseY()
     ClearScreen($000000)
     
     StartDrawing(ScreenOutput())
     
     For x = 0 To 50
          For y = 0 To 50
               If Karte(x,y)\typ = "1"
                    Box(x*20,y*20,20,20,RGB(0,233,0))
               ElseIf Karte(x,y)\typ = "0"
                    Box(x*20,y*20,20,20,RGB(0,0,233))
               EndIf
               
          Next
     Next
     
     StopDrawing()
     
     
     FlipBuffers()
     
Until KeyboardReleased(1)
End 
Danke schon mal im vor raus,
NathanielBlack
Benutzeravatar
ts-soft
Beiträge: 22292
Registriert: 08.09.2004 00:57
Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel
Wohnort: Berlin

Re: Hilfe beim "Point" Befehl

Beitrag von ts-soft »

Die Koordinaten sind 0 basiert, von höhe und weite ist also jeweils ein pixel abzuziehen :wink:
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.
Bild
NathanielBlack
Beiträge: 63
Registriert: 25.12.2009 18:48

Re: Hilfe beim "Point" Befehl

Beitrag von NathanielBlack »

Sehr nett, danke!


So, ich stehe grade voll auf dem Schlauch-.-

Code: Alles auswählen

     For x = ScrollX To ScrollX+50
          For y = ScrollY To ScrollY+30
               DrawingMode(#PB_2DDrawing_Outlined)
               Box(x*20,y*20,20,20,RGB(255,255,255))
               DrawingMode(#PB_2DDrawing_Default)
               If Karte(x,y)\typ = "1"
                    Box(x*20,y*20,20,20,RGB(0,233,0))
               ElseIf Karte(x,y)\typ = "0"
                    Box(x*20,y*20,20,20,RGB(0,0,233))
               EndIf
               
          Next
     Next
Wie mache ich, dass der kleine Kartenausschnitt immer rechts oben in der Ecke bleibt?

Ich weiß, dass es einfach ist, doch irgendwie komm ich nicht vom Schlauch runter-_-.

NathanielBlack
Antworten