Jump to content

I need help with moving a control


Recommended Posts

I want the script move the label until I press the spacebar. The main problem is that the label just disappears on me. Here is the script.

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        A.N.Other <myemail@nowhere.com>
;
; Script Function:
;   Template AutoIt script.
;
; ----------------------------------------------------------------------------
;y = hieth
;x = wieth
; Script Start - Add your code below here
#include <GuiConstants.au3>
$height = 400
$width = 400
$gui = GuiCreate("MyGUI", $width, $height,(@DesktopWidth-518)/2, (@DesktopHeight-388)/2 )
$Label = GuiCtrlCreateLabel("", 200, 200, 20, 20)
GUICtrlSetBkColor($label,0)
GuiSetState()
HotKeySet("{up}","up")
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case _IsPressed(38); the number 8 
    $pos = ControlGetPos($gui,"",$label)
    GUICtrlSetPos($label,$width,$pos[1] + 1)
    EndSelect
WEnd
Exit
Func up()
$pos = ControlGetPos($gui,"",$label)
For $a = $pos[1] To $height 
    GUICtrlSetPos($label,$width,$pos[1] + 1)
    Sleep(10)
    If _IsPressed(20) Then; space key
        ExitLoop
    EndIf
Next
EndFunc

Func _IsPressed($hexKey)
Local $aR, $bRv
$hexKey = '0x' & $hexKey
$aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)

If $aR[0] <> 0 Then
    $bRv = 1
Else
    $bRv = 0
EndIf

Return $bRv
EndFunc

.

Link to comment
Share on other sites

Change Func Up() to this...

Func up()
   While 1
      $pos = ControlGetPos($gui,"",$label)
      GUICtrlSetPos($label,$pos[0],$pos[1] - 1)
      If _IsPressed(20) Then ExitLoop
      Sleep(10)
   Wend
EndFunc
Edited by Burrup

qq

Link to comment
Share on other sites

Change Func Up() to this...

Func up()
   While 1
      $pos = ControlGetPos($gui,"",$label)
      GUICtrlSetPos($label,$pos[0],$pos[1] - 1)
      If _IsPressed(20) Then ExitLoop
      Sleep(10)
   Wend
EndFunc

<{POST_SNAPBACK}>

Thanks a million. I will be using alot of this in my next game; the classic snake game. If I make it.

.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...