Jump to content

Moving Around Multiple Graphic Controls


Recommended Posts

Look at this little test code i've built. It builds 2 squares and then moves them to the side. Looks ok to me, but watch what happens..

#include <GUIConstants.au3>

Dim $graphic[2][3]

GUICreate("test code", 600, 250, -1, -1, $WS_POPUP)
GUISetBkColor(0)

$graphic[0][0] = GUICtrlCreateGraphic(0, 0, 100, 100)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xffffff)
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 100, 100)

$graphic[1][0] = GUICtrlCreateGraphic(0, 150, 100, 100)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xffffff)
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 100, 100)

GUISetState()

Sleep(4000)

While 1
    $graphic[0][1] += 50
    GUICtrlSetPos($graphic[0][0], $graphic[0][1], $graphic[0][2])
    Sleep(100)
    
    $graphic[1][1] += 50
    GUICtrlSetPos($graphic[1][0], $graphic[1][1], $graphic[1][2])
    Sleep(100)
WEnd
Link to comment
Share on other sites

  • Developers

and you wanted this ?

#include <GUIConstants.au3>

Dim $graphic[2][3]

GUICreate("test code", 600, 250, -1, -1, $WS_POPUP)
GUISetBkColor(0)

$graphic[0][0] = GUICtrlCreateGraphic(0, 0, 100, 100)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xffffff)
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 100, 100)

$graphic[1][0] = GUICtrlCreateGraphic(0, 150, 100, 100)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xffffff)
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 100, 100)

GUISetState()

Sleep(4000)

While 1
    $graphic[0][1] += 50
    GUICtrlSetPos($graphic[0][0], $graphic[0][1], $graphic[0][2])
    Sleep(100)
    
    $graphic[1][1] += 50
    GUICtrlSetPos($graphic[1][0], $graphic[1][1], 150)
    Sleep(100)
WEnd

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

That's Right.

[Edit] I got it. It's the problem that i left a few vars in the array undefined, so when it moves to position "" it gives a error and somehow manages to remove the entire control.

I've now just added $graphic[0][1] = $xcoord (pre defined in function)

and ofcourse also for $graphic[0][2] = $ycoord

Thanks for making me realise my mistake.

Edited by Manadar
Link to comment
Share on other sites

  • Developers

That's Right.

So you need to set the correct value for $graphic[0][2] and $graphic[1][2].

They are both zero so both squares are located at the same spot after the first move.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...