Type löschen?

Übersicht BlitzBasic Beginners-Corner

Neue Antwort erstellen

N0X

Betreff: Type löschen?

BeitragMo, Feb 01, 2010 14:43
Antworten mit Zitat
Benutzer-Profile anzeigen
Hey!
Warum kann ich in meinem Code ein Fenster das schon bewegt wurde nicht mehr löschen?

Code: [AUSKLAPPEN]
AppTitle("Drag&Drop (nur ohne Drop)- Beispiel von SpionAtom")

Graphics 800,600,16,2
SetBuffer BackBuffer()

Global mouse_x,mouse_y,win=0

Type fenster
   Field x      ;..X-Position
   Field y      ;..Y-Position
   Field w      ;..Breite (Width)
   Field h      ;..Höhe (Height)
   Field n      ;..und Typ (ich habe 3 Typen)
End Type

dragStart = False
Repeat
   mouse_x = MouseX()
   mouse_y = MouseY()
   
   If (MouseDown(1)) And (Not dragStart) Then
      For f.fenster = Each fenster
         If mouseInRect(f\x, f\y, f\x + f\w, f\y + f\h) Then
            af.fenster = f
            dragStart = True
            oldmx = mouse_x
            oldmy = mouse_y
            oldfx = f\x
            oldfy = f\y
         End If
      Next
   End If
   
   If dragStart Then
      af\x = oldfx - oldmx + mouse_x
      af\y = oldfy - oldmy +  mouse_y
      If Not MouseDown(1) Then dragStart = False
   End If
   
   If KeyHit(57) Then
      If win<>0 Then
         win=0
         Delete f
      Else
         win=1
         f.fenster = New fenster
         f\x = 200
         f\y = 200
         f\w = 200
         f\h = 200
         f\n = 1
      EndIf
   EndIf
   
   Cls
   drawAllFenster()
   Flip
Until KeyHit(1)
End

Function createMap2()
   f.fenster = New fenster
   f\x = 200
   f\y = 200
   f\w = 200
   f\h = 200
   f\n = 1
End Function

Function drawAllFenster()
   For f.fenster = Each fenster
      drawFenster f\x, f\y, f\w, f\h, f\n
   Next
End Function

Function drawFenster(x, y, w, h, n = 0)
   Select n
      Case 1
            Color 0, 255, 0
            Rect x, y, w, h, 1
            Color 255, 0, 0
            Rect x + 2, y + 2, w - 4, h - 4, 1
            Color 255, 255, 255
            Rect x, y, w, h, 0
            Rect x + 2, y + 2, w - 4, h - 4, 0
         Case 2
            Color 255, 255, 0
            Rect x, y, w, h, 1
            Color 0, 255, 255
            Oval x, y, w, h, 1
            Color 255, 255, 255
            Rect x, y, w, h, 0
            Oval x, y, w, h, 0
         Default
            Color 255, 0, 255
            Rect x, y, w, h, 1
            Color 255, 255, 255
            Rect x, y, w, h, 0
   End Select
End Function

Function mouseInRect (x1, y1, x2, y2)
   If mouse_x < x1 Then Return False
   If mouse_x > x2 Then Return False
      If mouse_y < y1 Then Return False
      If mouse_y > y2 Then Return False
      Return True
End Function


Mfg,
N0X
Projekte: |Tibario| http://www.blitzforum.de/worklogs/325/ | 5%

Xeres

Moderator

BeitragMo, Feb 01, 2010 14:56
Antworten mit Zitat
Benutzer-Profile anzeigen
Wo und wann setzt du win, wo f?
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)

N0X

BeitragMo, Feb 01, 2010 15:41
Antworten mit Zitat
Benutzer-Profile anzeigen
Oh, ich vergesse viel zu viel... Surprised

Hier mit Variablensetzung:
Code: [AUSKLAPPEN]
AppTitle("Drag&Drop (nur ohne Drop)- Beispiel von SpionAtom")

Graphics 800,600,16,2
SetBuffer BackBuffer()

Global mouse_x,mouse_y,win=0

Type fenster
   Field x      ;..X-Position
   Field y      ;..Y-Position
   Field w      ;..Breite (Width)
   Field h      ;..Höhe (Height)
   Field n      ;..und Typ (ich habe 3 Typen)
End Type

Global f.fenster

dragStart = False
Repeat
   mouse_x = MouseX()
   mouse_y = MouseY()
   
   If (MouseDown(1)) And (Not dragStart) Then
      For f.fenster = Each fenster
         If mouseInRect(f\x, f\y, f\x + f\w, f\y + f\h) Then
            af.fenster = f
            dragStart = True
            oldmx = mouse_x
            oldmy = mouse_y
            oldfx = f\x
            oldfy = f\y
         End If
      Next
   End If
   
   If dragStart Then
      af\x = oldfx - oldmx + mouse_x
      af\y = oldfy - oldmy +  mouse_y
      If Not MouseDown(1) Then dragStart = False
   End If
   
   If KeyHit(57) Then
      If win<>0 Then
         win=0
         Delete f
      Else
         win=1
         f.fenster = New fenster
         f\x = 200
         f\y = 200
         f\w = 200
         f\h = 200
         f\n = 1
      EndIf
   EndIf
   
   Cls
   drawAllFenster()
   Flip
Until KeyHit(1)
End

Function createMap2()
   f.fenster = New fenster
   f\x = 200
   f\y = 200
   f\w = 200
   f\h = 200
   f\n = 1
End Function

Function drawAllFenster()
   For f.fenster = Each fenster
      drawFenster f\x, f\y, f\w, f\h, f\n
   Next
End Function

Function drawFenster(x, y, w, h, n = 0)
   Select n
      Case 1
            Color 0, 255, 0
            Rect x, y, w, h, 1
            Color 255, 0, 0
            Rect x + 2, y + 2, w - 4, h - 4, 1
            Color 255, 255, 255
            Rect x, y, w, h, 0
            Rect x + 2, y + 2, w - 4, h - 4, 0
         Case 2
            Color 255, 255, 0
            Rect x, y, w, h, 1
            Color 0, 255, 255
            Oval x, y, w, h, 1
            Color 255, 255, 255
            Rect x, y, w, h, 0
            Oval x, y, w, h, 0
         Default
            Color 255, 0, 255
            Rect x, y, w, h, 1
            Color 255, 255, 255
            Rect x, y, w, h, 0
   End Select
End Function

Function mouseInRect (x1, y1, x2, y2)
   If mouse_x < x1 Then Return False
   If mouse_x > x2 Then Return False
      If mouse_y < y1 Then Return False
      If mouse_y > y2 Then Return False
      Return True
End Function


Win steht oben bei der 3. Zeile, win=0.
Projekte: |Tibario| http://www.blitzforum.de/worklogs/325/ | 5%

Xeres

Moderator

BeitragMo, Feb 01, 2010 16:22
Antworten mit Zitat
Benutzer-Profile anzeigen
Also, generell finde ich das etwas seltsam, da immer nur 1 Fenster gleichzeitig existiert - win schaltet ja um von generieren zu löschen.
f wählst du nicht aus, es ist nicht sicher gestellt, dass da überhaupt ein Objekt drin ist, denn nach einer For...Each schleife ist f Null.
Probiere mal:
BlitzBasic: [AUSKLAPPEN]
Delete Last fenster

Weder win noch f müssen global sein.
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)

N0X

BeitragMo, Feb 01, 2010 17:40
Antworten mit Zitat
Benutzer-Profile anzeigen
Perfekt, funktioniert!
Danke, wusste garnicht das es soeinen Befehl gibt! Embarassed

Mfg,
N0X
Projekte: |Tibario| http://www.blitzforum.de/worklogs/325/ | 5%

Neue Antwort erstellen


Übersicht BlitzBasic Beginners-Corner

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group