Was ist Falsch? (Gui)

  • Hallo an alle,

    habe mal aus langeweile etwas angefangen und wollte es ein wenig erweitern. Undzwar geht es um eine Gui, wo man mit den Pfeiltasten (links,rechts) ein Label bewegen kann und mit der Leertaste ein "Sprung" realisiert werden soll. Klappt an sich leider nicht ganz wie ich es will.
    Hier erst einmal der Code

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <Misc.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $posx = 0, $posy = @DesktopHeight-300, $speed = 10, $delay = 50

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("SB Game", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
    GUISetBkColor(0xCDAD00)
    $mainmenu = GUICtrlCreateMenu("Datei")
    $exititem = GUICtrlCreateMenuItem("Beenden", $mainmenu)
    $label1 = GUICTrlCreateLabel("",0,@DesktopHeight,60,300)
    GUICTrlSEtBkColor(-1,0x000000)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $exititem
    Exit
    EndSwitch
    if _IsPressed("25") Then _left()
    If _IsPressed("27") Then _right()
    if _IsPressed("20") Then _springen()
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _springen()
    Local $delay = 50
    For $i = 1 to 20
    Switch _IsPressed("27")
    case 1
    _right()
    $delay = 0
    Case Else
    $delay = 50
    EndSwitch
    Switch _IsPressed("25")
    case 1
    _left()
    $delay = 0
    Case Else
    $delay = 50
    EndSwitch
    $posy = $posy -10
    GUICtrlSetPos($label1,$posx,$posy)
    sleep ($delay)
    Next
    Local $delay = 50
    For $i = 1 to 20
    Switch _IsPressed("27")
    case 1
    _right()
    $delay = 0
    Case Else
    $delay = 50
    EndSwitch
    Switch _IsPressed("25")
    case 1
    _left()
    $delay = 0
    Case Else
    $delay = 50
    EndSwitch
    $posy = $posy +10
    GUICtrlSetPos($label1,$posx,$posy)
    sleep ($delay)
    Next
    Local $delay = 50
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _right()
    $posx += $speed
    If $posx >= @DesktopWidth Then $posx = 0
    GUICtrlSetPos($label1,$posx,$posy)
    Sleep($delay)
    EndFunc ;==>_right

    [/autoit] [autoit][/autoit] [autoit]

    Func _left()
    $posx -= $speed
    If $posx <= 0 Then $posx = @DesktopWidth
    GUICtrlSetPos($label1,$posx,$posy)
    Sleep($delay)
    EndFunc ;==>_left

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    Exit
    EndFunc

    [/autoit]

    ACHTUNG!!! Noob am Coden (Code ist nicht schön ich weiss)

    Das Problem ist, das jeweils das 2. Switch in diesem Fall

    [autoit]

    Switch _IsPressed("25")
    case 1
    _left()
    $delay = 0
    Case Else
    $delay = 50
    EndSwitch

    [/autoit]


    Probleme macht, wenn ich im Sprung nach Rechts drücke ruckelt er... nach links gehts einwandfrei. Wenn ich die Switches tausche dann ruckelt es Links.
    Liegt es an Switch ? hatte es vorher mit If und das ging auch nicht :(
    Meine Frage: Kann man es anders realisieren? das es für beide Richtungen geht ?

    • Offizieller Beitrag

    Probier es mal so:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <Misc.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $posx = 0, $posy = @DesktopHeight - 300, $speed = 10, $delay = 50

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("SB Game", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
    GUISetBkColor(0xCDAD00)
    $mainmenu = GUICtrlCreateMenu("Datei")
    $exititem = GUICtrlCreateMenuItem("Beenden", $mainmenu)
    $label1 = GUICtrlCreateLabel("", 0, @DesktopHeight, 60, 300)
    GUICtrlSetBkColor(-1, 0x000000)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $exititem
    Exit
    EndSwitch
    If _IsPressed("25") Then _left()
    If _IsPressed("27") Then _right()
    If _IsPressed("20") Then _springen()
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _springen()
    Local $delay = 50
    For $i = 1 To 20
    If _IsPressed("27") Then _right()
    If _IsPressed("25") Then _left()

    [/autoit] [autoit][/autoit] [autoit]

    $posy = $posy - 10
    GUICtrlSetPos($label1, $posx, $posy)
    Sleep($delay)
    Next
    Local $delay = 50
    For $i = 1 To 20
    If _IsPressed("27") Then _right()
    If _IsPressed("25") Then _left()
    $posy = $posy + 10
    GUICtrlSetPos($label1, $posx, $posy)
    Sleep($delay)
    Next
    Local $delay = 50
    EndFunc ;==>_springen

    [/autoit] [autoit][/autoit] [autoit]

    Func _right()
    $posx += $speed
    If $posx >= @DesktopWidth Then $posx = 0
    GUICtrlSetPos($label1, $posx, $posy)
    Sleep($delay)
    EndFunc ;==>_right

    [/autoit] [autoit][/autoit] [autoit]

    Func _left()
    $posx -= $speed
    If $posx <= 0 Then $posx = @DesktopWidth
    GUICtrlSetPos($label1, $posx, $posy)
    Sleep($delay)
    EndFunc ;==>_left

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    Exit
    EndFunc ;==>_Exit

    [/autoit]

    Deine Switches waren ein wenig kofus, ich denke so sollte es gehen .

  • So ist es, wie ich es vorher hatte.. Jedoch ist der Sprung so etwas langsam wenn man gleichzeitig noch zur Seite drückt. Deswegen hatte ich die $delay auf 0 gesetzt, wenn im Sprung noch "rechts" oder "links" gedrückt wurde. Klappt ja in meinem Beispiel auch, nur leider immer nur für eine Richtung. (kommt drauf an welcher switch zuerst kommt (Links, oder Rechts). Trotzdem danke ich probiere mal weiter

  • Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <Misc.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $posx = 0, $posy = @DesktopHeight - 300, $speed = 10, $delay = 50

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("SB Game", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
    GUISetBkColor(0xCDAD00)
    $mainmenu = GUICtrlCreateMenu("Datei")
    $exititem = GUICtrlCreateMenuItem("Beenden", $mainmenu)
    $label1 = GUICtrlCreateLabel("", 0, @DesktopHeight, 60, 300)
    GUICtrlSetBkColor(-1, 0x000000)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $exititem
    Exit
    EndSwitch
    If _IsPressed("25") Then _left()
    If _IsPressed("27") Then _right()
    If _IsPressed("20") Then _springen()
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _springen()
    Local $delay = 50
    For $i = 1 To 20
    If _IsPressed("27") Then _right()
    If _IsPressed("25") Then _left()

    [/autoit] [autoit][/autoit] [autoit]

    $posy = $posy - 10
    GUICtrlSetPos($label1, $posx, $posy)
    Sleep($delay)
    Next
    Local $delay = 50
    For $i = 1 To 20
    If _IsPressed("27") Then _right()
    If _IsPressed("25") Then _left()
    $posy = $posy + 10
    GUICtrlSetPos($label1, $posx, $posy)
    Sleep($delay)
    Next
    Local $delay = 50
    EndFunc ;==>_springen

    [/autoit] [autoit][/autoit] [autoit]

    Func _right()
    $posx += $speed
    If $posx >= @DesktopWidth Then $posx = 0
    GUICtrlSetPos($label1, $posx, $posy)
    EndFunc ;==>_right

    [/autoit] [autoit][/autoit] [autoit]

    Func _left()
    $posx -= $speed
    If $posx <= 0 Then $posx = @DesktopWidth
    GUICtrlSetPos($label1, $posx, $posy)
    EndFunc ;==>_left

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    Exit
    EndFunc ;==>_Exit

    [/autoit]

    mfg. Jam00

  • Jam00 deins ist leider auch nicht so, wie ich es mir vorgestellt hatte :_( habe selber noch ein wenig rumprobiert. Bin jetzt soweit, dass er flüssig in beide Richtungen springt. Jedoch ist noch ein bug da. Wenn ich nach rechts Springe und dann die Pfeiltaste Loslasse, Springt er sofort Nach ganz oben / nach ganz unten. Könnt es ja mal selber angucken. Vielleicht weiss ja einer zu Helfen. Danke

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <Misc.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $posx = 0, $posy = @DesktopHeight - 300, $speed = 10, $delay = 50

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("SB Game", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
    GUISetBkColor(0xCDAD00)
    $mainmenu = GUICtrlCreateMenu("Datei")
    $exititem = GUICtrlCreateMenuItem("Beenden", $mainmenu)
    $label1 = GUICtrlCreateLabel("", 0, @DesktopHeight, 60, 300)
    GUICtrlSetBkColor(-1, 0x000000)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $exititem
    Exit
    EndSwitch
    If _IsPressed("25") Then _left()
    If _IsPressed("27") Then _right()
    If _IsPressed("20") Then _springen()
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _springen()
    Local $delay = 50
    For $i = 1 To 20
    If _IsPressed("27") Then
    _right()
    $delay = 0
    EndIf
    If _IsPressed("25") Then
    _left()
    $delay = 0
    EndIf
    $posy = $posy - 10
    GUICtrlSetPos($label1, $posx, $posy)
    Sleep($delay)
    Next
    Local $delay = 50
    For $i = 1 To 20
    If _IsPressed("27") Then
    _right()
    $delay = 0
    EndIf
    If _IsPressed("25") Then
    _left()
    $delay = 0
    EndIf
    $posy = $posy + 10
    GUICtrlSetPos($label1, $posx, $posy)
    Sleep($delay)
    Next
    Local $delay = 50
    EndFunc ;==>_springen

    [/autoit] [autoit][/autoit] [autoit]

    Func _right()
    $posx += $speed
    If $posx >= @DesktopWidth Then $posx = 0
    GUICtrlSetPos($label1, $posx, $posy)
    Sleep($delay)
    EndFunc ;==>_right

    [/autoit] [autoit][/autoit] [autoit]

    Func _left()
    $posx -= $speed
    If $posx <= 0 Then $posx = @DesktopWidth
    GUICtrlSetPos($label1, $posx, $posy)
    Sleep($delay)
    EndFunc ;==>_left

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    Exit
    EndFunc ;==>_Exit

    [/autoit]

    Bin jetzt erstmal ein wenig Weg. Freue mich trotzdem über Lösungsansätze Tips oder sonstige Hilfestellung. MfG SiLenCa