ich bin neu in PB und habe die ersten Probleme, ich habe ein Programm
geschrieben in der Zeitabläufe eine Rolle spielen. Bisher habe ich dieses über
delay (1000) oder so gelöst. Leider ist dies wohl nicht ganz glücklich denn
das Programm reagiert sehr stockend.
Das Ampelübeprog. PB 3.30
Code: Alles auswählen
; Purebasic Ver. 3.30
;
; Öffnet ein Wenster
; WindowID = OpenWindow(#Window, x, y, InnereBreite, InnereHöhe, Flags, Titel$)
; Mögliche Flags sind:
; #PB_Window_SystemMenu : Schaltet das System-Menü in der Fenster-Titelzeile ein.
; #PB_Window_MinimizeGadget : Fügt das Minimieren-Gadget der Fenster-Titelzeile hinzu. #PB_Window_System wird automatisch hinzugefügt.
; #PB_Window_MaximizeGadget : Fügt das Maximieren-Gadget der Fenster-Titelzeile hinzu. #PB_Window_System wird automatisch hinzugefügt.
; #PB_Window_SizeGadget : Fügt das Größenänderungs-Gadget zum Fenster hinzu.
; #PB_Window_Invisible : Erstellt ein Fenster, zeigt es aber nicht an. Wird nicht unter AmigaOS unterstützt.
; #PB_Window_TitleBar : Erstellt ein Fenster mit einer Titelzeile.
; #PB_Window_BorderLess : Erstellt ein Fenster ohne jegliche Ränder.
If OpenWindow(0, 100, 300, 300, 360, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "Ampel")
; This is the 'event loop'. All the user actions are processed here.
; It's very easy to understand: when an action occurs, the EventID
; isn't 0 and we just have to see what have happened...
;
Raus:
If CreateGadgetList(WindowID())
ButtonGadget(1,20,20,100,20,"Start");Knopf erstellen
ButtonGadget(2,130,20,110,20,"Stoppen");Knopf erstellen
EndIf
Repeat ;wiederhole bis Until Quit=1
EventID.l = WaitWindowEvent() ; Macht aus EventID.l long und übergibt den Wert aus WaitWindowEvent()
;Wartet bis ein Ereignis auftritt. Es ist die selbe Funktion wie WindowEvent(),
;hält aber die Programmausführung an, was sehr wichtig in einer Multitasking
;Umgebung ist. Eine Applikation sollte möglichst immer diesen Befehl anstelle von
;WindowEvent()benutzen. Für weitere Informationen, sehen Sie die Dokumentation zu WindowEvent()
If EventID = #PB_Event_CloseWindow ; Die Windows schließen Variable wird abgefragt
Quit = 1 ; wenn ja dann Quit=1 sonst nichts
EndIf
If EventID = #PB_Event_Gadget Or zahl=1 Or zahl=2
If EventGadgetID()=1 ; wurde gadget 1 angeklickt ?
Zahl.l=1
EndIf
If EventGadgetID()=2 ; wurde gadget 1 angeklickt ?
Zahl=2
EndIf
If Zahl=1
Delay(2000)
Gosub gruen
Delay(2000)
Gosub rot
EndIf
If Zahl=2
Delay(2000)
Gosub gelb
Delay(2000)
Gosub grau
EndIf
EndIf
Until Quit = 1 ; Schleife oben wird beendet wenn Quit=1
EndIf ; endif des Fensterbefehles
End ; All the opened windows are closed automatically by PureBasic
gruen:
StartDrawing(WindowOutput())
Box(50,63,50,142, RGB(0,2,0)) ; eine schwarze Box(x, y, Breite, Höhe [, Farbe])
Circle(75,176,20,RGB(0,155,0)) ; Circle(x, y, Radius [, Farbe]) ein grüner Kreis
Circle(75,132,20,RGB(155,155,155)) ; Circle(x, y, Radius [, Farbe]) ein grauer Kreis
Circle(75,90,20,RGB(155,155,155)) ; Circle(x, y, Radius [, Farbe]) ein grauer Kreis
StopDrawing() ; This is absolutely needed when the drawing operations are finished !!! Never forget it !
Return
rot:
StartDrawing(WindowOutput())
Box(50,63,50,142, RGB(0,2,0)) ; eine schwarze Box(x, y, Breite, Höhe [, Farbe])
Circle(75,176,20,RGB(155,155,155)) ; Circle(x, y, Radius [, Farbe]) ein grüner Kreis
Circle(75,132,20,RGB(155,155,155)) ; Circle(x, y, Radius [, Farbe]) ein grauer Kreis
Circle(75,90,20,RGB(255,0,0)) ; Circle(x, y, Radius [, Farbe]) ein grauer Kreis
StopDrawing() ; This is absolutely needed when the drawing operations are finished !!! Never forget it !
Return
rot_gelb:
StartDrawing(WindowOutput())
Box(50,63,50,142, RGB(0,2,0)) ; eine schwarze Box(x, y, Breite, Höhe [, Farbe])
Circle(75,176,20,RGB(155,155,155)) ; Circle(x, y, Radius [, Farbe]) ein grüner Kreis
Circle(75,132,20,RGB(255,255,0)) ; Circle(x, y, Radius [, Farbe]) ein grauer Kreis
Circle(75,90,20,RGB(255,0,0)) ; Circle(x, y, Radius [, Farbe]) ein grauer Kreis
StopDrawing() ; This is absolutely needed when the drawing operations are finished !!! Never forget it !
Return
gelb:
StartDrawing(WindowOutput())
Box(50,63,50,142, RGB(0,2,0)) ; eine schwarze Box(x, y, Breite, Höhe [, Farbe])
Circle(75,176,20,RGB(155,155,155)) ; Circle(x, y, Radius [, Farbe]) ein grüner Kreis
Circle(75,132,20,RGB(255,255,0)) ; Circle(x, y, Radius [, Farbe]) ein grauer Kreis
Circle(75,90,20,RGB(155,155,155)) ; Circle(x, y, Radius [, Farbe]) ein grauer Kreis
StopDrawing() ; This is absolutely needed when the drawing operations are finished !!! Never forget it !
Return
grau:
StartDrawing(WindowOutput())
Box(50,63,50,142, RGB(0,2,0)) ; eine schwarze Box(x, y, Breite, Höhe [, Farbe])
Circle(75,176,20,RGB(155,155,155)) ; Circle(x, y, Radius [, Farbe]) ein grüner Kreis
Circle(75,132,20,RGB(155,155,155)) ; Circle(x, y, Radius [, Farbe]) ein grauer Kreis
Circle(75,90,20,RGB(155,155,155)) ; Circle(x, y, Radius [, Farbe]) ein grauer Kreis
StopDrawing() ; This is absolutely needed when the drawing operations are finished !!! Never forget it !
Return
habe ich nicht begriffen, oder wüßte nicht wie ich es einfügen sollte.
Gruß
Guido