Dyson Posted November 17, 2008 Share Posted November 17, 2008 I am attempting to recreate pong using Autoit, and I don't want any ideas on how to do this, i need to figure this out on my own... anyways, for now i have decided to use Guictrlcreatebutton for my pong paddles however the way that i thought about moving them isn't working and i've played around and can't figure it out. I will include a copy of my script and I hope that someone can figure out how to manipulate the button to move up and down. CODE#include <GUIConstantsEx.au3> hotkeyset ("{down}", "_down") hotkeyset ("{UP}", "_up") func _Down() EndFunc func _up() EndFunc guicreate ("", 1020, 705) guisetbkcolor (0x000000) GUISetState (@sw_Show) $start = GUICtrlCreateButton ("Start", 0, 0, 510, 60) $exit = GUICtrlCreateButton ("Exit", 510, 0, 510, 60) while 1 $msg = Guigetmsg() select case $msg = $Gui_Event_Close msgbox (0, "Goodbye", "Goodbye", 2) guidelete() Exit case $msg = $exit msgbox (0, "Goodbye", "Goodbye", 2) Guidelete() Exit case $msg = $start ExitLoop EndSelect WEnd guidelete() guicreate ("", 1020, 710) guisetbkcolor (0x000000) guisetstate (@sw_Show) $top = 150 if _down() Then $top +=5 ElseIf _up() Then $top -=5 EndIf $paddle1 = guictrlcreatebutton ("", 0, $top, 10, 80) $paddle2 = Guictrlcreatebutton ("", 1010, 540, 10, 80) while 1 $msg = Guigetmsg() Select case $msg = $Gui_Event_Close guidelete() Exit EndSelect WEnd Link to comment Share on other sites More sharing options...
Achilles Posted November 17, 2008 Share Posted November 17, 2008 Try GUICtrlSetPos or ControlMove.. They should both do want you want. My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
oMBRa Posted November 17, 2008 Share Posted November 17, 2008 (edited) Little example: expandcollapse popup#include <GUIConstantsEx.au3> HotKeySet('{LEFT}', 'MoveButton') HotKeySet('{RIGHT}', 'MoveButton') HotKeySet('{DOWN}', 'MoveButton') HotKeySet('{UP}', 'MoveButton') Global $Increase = 50 Global $Width = 400 Global $Height = 400 $MyGUI = GUICreate('Moving Button', $Width, $Height) $Button = GUICtrlCreateButton('Move', 50, 50, 50, 30) GUISetState() While 1 $nMsg = GUIGetMsg() If $nMsg = $GUI_EVENT_CLOSE Then Exit EndIf WEnd Func MoveButton() $Pos = ControlGetPos($MyGUI, '', $Button) $Command = @HotKeyPressed Switch $Command Case '{LEFT}' If $Pos[0] >= $Increase Then GUICtrlSetPos($Button, $Pos[0] - $Increase, $Pos[1]) ElseIf $Pos[0] - $Increase < $Increase Then GUICtrlSetPos($Button, 0, $Pos[1]) EndIf Case '{RIGHT}' If $Pos[0] + $Pos[2] <= $Width - $Increase Then GUICtrlSetPos($Button, $Pos[0] + $Increase, $Pos[1]) ElseIf $Pos[0] + $Pos[2] >= $Width - $Increase Then GUICtrlSetPos($Button, $Width - $Pos[2], $Pos[1]) EndIf Case '{DOWN}' If $Pos[1] + $Pos[3] <= $Height - $Increase Then GUICtrlSetPos($Button, $Pos[0], $Pos[1] + $Increase) ElseIf $Pos[1] + $Pos[3] >= $Height - $Increase Then GUICtrlSetPos($Button, $Pos[0], $Height - $Pos[3]) EndIf Case '{UP}' If $Pos[1] >= $Increase Then GUICtrlSetPos($Button, $Pos[0], $Pos[1] - $Increase) ElseIf $Pos[1] <= $Increase Then GUICtrlSetPos($Button, $Pos[0], 0) EndIf EndSwitch EndFunc ;==>MoveButton Edited November 17, 2008 by oMBra Link to comment Share on other sites More sharing options...
Dyson Posted November 17, 2008 Author Share Posted November 17, 2008 Thanks it worked out, now i'm trying to automate the movement of the ball but as of right know i'm still playing around and don't need any help. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now