Sign in to follow this  
Followers 0
quick_sliver007

I need help with moving a control

5 posts in this topic

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


.

Share this post


Link to post
Share on other sites



For the up function, try:

GUICtrlSetPos($label,$pos[0],$pos[1] - 1)

<{POST_SNAPBACK}>

Looks like I was down instead of up, but I still have the same problem. The label just disappears.

.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

[u]Old Projects:[/u]A3MORGB2Hex[u]Old Functions:[/u]_TimeAdd/_TimeSub_AddComma_BubbleSort _RippleSort "He who does not understand your silence will probably not understand your words." - Elbert Hubbard.

Share this post


Link to post
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.

.

Share this post


Link to post
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
Sign in to follow this  
Followers 0