Jump to content

Interacting with Multiple Controls


PickPocketz
 Share

Recommended Posts

I'm working on a new project that is going to immitate a RPG I play online. It's a pretty simple Isometric/Tile Based project and I am trying to figure out how to target all the controls on the screen (mainly pic controls) so that when I click and drag they all will move in the same fashion. I know I could go through and specifically pick on each control but I was looking for a way to grab them all in a general manner without pointing out each variable name. I figure I could put them all in an array and some how loop through the array but If there is a quicker means to this I would love to know how. I've searched through the forum but I think the words I search are just too general. Any help?

Link to comment
Share on other sites

Well I've set it up using an array but I'm having timing problems. While moving the mouse the controls don't follow through correctly...

Here is an example of my script:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
HotKeySet("{ESC}", "end")
Const $title = "_Project"
$wX = @DesktopWidth / 3
$wY = @DesktopHeight / 3
Dim $Array[3]
Dim $mArray[6]
GUICreate($title, $wX, $wY, 0, 0)
GUISetBkColor(0x000000)
$Array[0] = GUICtrlCreatePic(@ScriptDir & "ball_red_01.jpg", 50, 100, 30, 30)
$Array[1] = GUICtrlCreatePic(@ScriptDir & "ball_red_01.jpg", 100, 100, 30, 30)
$Array[2] = GUICtrlCreatePic(@ScriptDir & "ball_red_01.jpg", 150, 100, 30, 30)
GUISetState()
GUICreate($title & " Vars:", 200, 400, @DesktopWidth - 205, 0)
$mProdX = GUICtrlCreateLabel("X Change: ", 5, 5, 190, 20)
$mProdY = GUICtrlCreateLabel("Y Change: ", 5, 25, 190, 20)
GUISetState()
While 1
$msg = GUIGetMsg()
$uArray = UBound($Array)

Select
case $msg = $GUI_EVENT_CLOSE
  Exit
case _IsPressed(01)
  drag_screen()
case _isPressed(20)
  MsgBox(2, $title, $uArray, 10)
EndSelect

WEnd
Func drag_screen()
$ii = 0
For $i = 0 To $uArray - 1 Step 1
  $_mouse = MouseGetPos()
  $mArray[0] = $_mouse[0]
  $mArray[2] = $_mouse[1]
 
  Sleep(1)
 
  $_mouse = MouseGetPos()
  $mArray[1] = $_mouse[0]
  $mArray[3] = $_mouse[1]

  $mArray[4] = $mArray[0] - $mArray[1]
  $mArray[5] = $mArray[2] - $mArray[3]
 
  GUICtrlSetData($mProdX, "X Change: " & $mArray[4])
  GUICtrlSetData($mProdY, "Y Change: " & $mArray[5])
 
  $_Array = ControlGetPos($title, "", $Array[$i])
 
Do
 
  GUICtrlSetPos($Array[$i], $_Array[0] + $mArray[4], $_Array[1] + $mArray[5])
  $ii += 1
 
Until $ii = $uArray - 1
 
  $ii = 0
 
Next
EndFunc
Func end()
Exit
EndFunc

Ofcourse you will have to fit in your own pictures and change the directory if you wish to run 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

×
×
  • Create New...