Ich hab mal wieder ein Problem mit meinen kleinen Starfield. Am Anfang läuft alles wunderbar, doch nach ein bis zwei Minuten geht die Prozessorauslastung von ca. 20% auf 30% und das ganze fängt an zu ruckeln. Könnte das jemand mal testen, ob das bei Ihm auch so ist? (Vielleicht liegt es ja an meinem Win Vista).
Code: Alles auswählen
; ========================================================================
Enumeration
#myWindowID
EndEnumeration
#myWindowWidth = 800 : #myWindowHeight = 600 : #myStarQuantity = 100
#myStarSpeedF = 1.5 : #myStarSpeedM = 1 : #myStarSpeedB = 0.5
#myTwinkleMaxGrey = 100 : #myTwinkleSpeed = 1 : #myTwinkleQuantity = 250
; ========================================================================
Structure ntStarType
PositionX.f
PositionY.f
EndStructure
Structure ntTwinkleType
PositionX.w
PositionY.w
GreyValue.c
BrightOrDark.b
EndStructure
Global Dim TwinkleLayer.ntTwinkleType(#myTwinkleQuantity)
Global Dim StarsLayerF.ntStarType(#myStarQuantity)
Global Dim StarsLayerM.ntStarType(#myStarQuantity)
Global Dim StarsLayerB.ntStarType(#myStarQuantity)
Global myEvent.l = 0 : Global myKeyPressed.l = 0
Global myCounterA.w = 0
; ========================================================================
Procedure DrawAllThings()
ClearScreen(RGB(0, 0, 0))
StartDrawing(ScreenOutput())
; --- Den animierten Hintergrund berechnen und zeichnen ----------
For myCounterA = 0 To #myTwinkleQuantity Step 1
If TwinkleLayer(myCounterA)\BrightOrDark = 0
If (TwinkleLayer(myCounterA)\GreyValue - #myTwinkleSpeed) < 0
TwinkleLayer(myCounterA)\PositionX = Int(Random(#myWindowWidth - 1))
TwinkleLayer(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))
TwinkleLayer(myCounterA)\GreyValue = 0
TwinkleLayer(myCounterA)\BrightOrDark = 1
Else
TwinkleLayer(myCounterA)\GreyValue = TwinkleLayer(myCounterA)\GreyValue - #myTwinkleSpeed
EndIf
Else
If (TwinkleLayer(myCounterA)\GreyValue + #myTwinkleSpeed) > #myTwinkleMaxGrey
TwinkleLayer(myCounterA)\GreyValue = TwinkleLayer(myCounterA)\GreyValue - #myTwinkleSpeed
TwinkleLayer(myCounterA)\BrightOrDark = 0
Else
TwinkleLayer(myCounterA)\GreyValue = TwinkleLayer(myCounterA)\GreyValue + #myTwinkleSpeed
EndIf
EndIf
Plot(TwinkleLayer(myCounterA)\PositionX, TwinkleLayer(myCounterA)\PositionY, RGB(TwinkleLayer(myCounterA)\GreyValue, TwinkleLayer(myCounterA)\GreyValue, TwinkleLayer(myCounterA)\GreyValue))
Next myCounterA
; --- Den Hintergrundlayer berechnen und zeichnen ----------------
For myCounterA = 0 To #myStarQuantity Step 1
If (StarsLayerB(myCounterA)\PositionX - #myStarSpeedB) < 0
StarsLayerB(myCounterA)\PositionX = #myWindowWidth -1
StarsLayerB(myCounterA)\PositionY = Int(Random(#myWindowHeight -1))
Else
StarsLayerB(myCounterA)\PositionX = StarsLayerB(myCounterA)\PositionX - #myStarSpeedB
EndIf
Plot(StarsLayerB(myCounterA)\PositionX, StarsLayerB(myCounterA)\PositionY, RGB(150, 150, 150))
Next myCounterA
; --- Den mittleren Layer berechnen und zeichnen ------------------
For myCounterA = 0 To #myStarQuantity Step 1
If (StarsLayerM(myCounterA)\PositionX - #myStarSpeedM) < 0
StarsLayerM(myCounterA)\PositionX = #myWindowWidth -1
StarsLayerM(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))
Else
StarsLayerM(myCounterA)\PositionX = StarsLayerM(myCounterA)\PositionX - #myStarSpeedM
EndIf
Plot(StarsLayerM(myCounterA)\PositionX, StarsLayerM(myCounterA)\PositionY, RGB(200, 200, 200))
Next myCounterA
; --- Den Vordergrund Layer berechnen und zeichnen ---------------
For myCounterA = 0 To #myStarQuantity Step 1
If (StarsLayerF(myCounterA)\PositionX - #myStarSpeedF) < 0
StarsLayerF(myCounterA)\PositionX = #myWindowWidth -1
StarsLayerF(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))
Else
StarsLayerF(myCounterA)\PositionX = StarsLayerF(myCounterA)\PositionX - #myStarSpeedF
EndIf
Plot(StarsLayerF(myCounterA)\PositionX, StarsLayerF(myCounterA)\PositionY, RGB(250, 250, 250))
Next myCounterA
; --- Textausgabe ------------------------------------------------
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(15, 15, "Ecs zum beenden", RGB(80, 80, 80), RGB(0, 0, 0))
StopDrawing()
FlipBuffers()
EndProcedure
; ========================================================================
If Not InitSprite()
MessageRequester("Sternenfeld", "Es ist ein DirectX Fehler aufgetreten - InitSprite( )", #PB_MessageRequester_Ok ) : End
EndIf
If Not InitKeyboard()
MessageRequester("Sternenfeld", "Es ist ein DirectX Fehler aufgetreten - InitKeyboard( )", #PB_MessageRequester_Ok ) : End
EndIf
If Not OpenWindow(#myWindowID, 0, 0, #myWindowWidth, #myWindowHeight, "Sternenfeld", #PB_Window_ScreenCentered|#PB_Window_BorderLess)
MessageRequester("Sternenfeld", "Es ist ein Fehler aufgetreten - OpenWindow( )", #PB_MessageRequester_Ok ) : End
EndIf
If Not OpenWindowedScreen(WindowID(#myWindowID), 0, 0, #myWindowWidth, #myWindowHeight, 0, 0, 0)
MessageRequester("Sternenfeld", "Es ist ein Fehler aufgetreten - OpenWindowedScreen( )", #PB_MessageRequester_Ok ) : End
EndIf
; ========================================================================
; --- Den animierten Hintergrund initialisieren ------------------------
For myCounterA = 0 To #myTwinkleQuantity Step 1
TwinkleLayer(myCounterA)\PositionX = Int(Random(#myWindowWidth - 1))
TwinkleLayer(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))
TwinkleLayer(myCounterA)\GreyValue = Int(Random(#myWindowWidth + 1))
TwinkleLayer(myCounterA)\BrightOrDark = Int(Random(1))
Next myCounterA
; --- Die 3 Sternenfeld Layer erstmalig initialisieren -----------------
For myCounterA = 0 To #myStarQuantity Step 1
StarsLayerB(myCounterA)\PositionX = Int(Random(#myWindowWidth - 1))
StarsLayerB(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))
StarsLayerM(myCounterA)\PositionX = Int(Random(#myWindowWidth -1))
StarsLayerM(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))
StarsLayerF(myCounterA)\PositionX = Int(Random(#myWindowWidth -1))
StarsLayerF(myCounterA)\PositionY = Int(Random(#myWindowHeight -1))
Next myCounterA
; ========================================================================
Repeat
myEvent = WaitWindowEvent(10)
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
myKeyPressed = #PB_Key_Escape
EndIf
DrawAllThings()
Until myKeyPressed = #PB_Key_Escape
; ========================================================================
End
; ========================================================================
Captain Qwark