Sign in to follow this  
Followers 0
cppman

Having trouble with my script

9 posts in this topic

#1 ·  Posted (edited)

Im trying to make $controlID move to the coordinates $x and $y.

could anyone help me out, to tell me how i could do this?

Global $Image, $Width, $Height, $StartX, $StartY
Func SpriteCreate($Image, $Width, $Height, $StartX, $StartY)
    Global $controlID
    $controlID = GUICtrlCreatePic($Image, $StartX, $StartY, $Width, $Height)
    If $controlID Then
        Return $controlID
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc

Func SpriteMove($controlID, $x, $y); move to x and y position

EndFunc

GUICreate("Game Sample", 500, 500, -1, -1)
GUISetBkColor(0x000000)
GUIsetState()
$Sprite = SpriteCreate("sprite.jpg", 25, 25, 15, 15)
sleep(1000)
SpriteMove($Sprite, 200, 15)
While 1
WEnd

yeah, i no, my functions should be after the while loop. but i did this so because i was in the middle of writing this udf and wanted to test it out real quick....

Edited by CHRIS95219

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include <GuiConstants.au3>

Global $Image, $Width, $Height, $StartX, $StartY
Func SpriteCreate($Image, $Width, $Height, $StartX, $StartY)
    Global $controlID
    $controlID = GUICtrlCreatePic($Image, $StartX, $StartY, $Width, $Height)
    If $controlID Then
        Return $controlID
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc  ;==>SpriteCreate

Func SpriteMove($controlID, $x, $y); move to x and y position
    GUICtrlSetPos($controlID, $x, $y)
EndFunc  ;==>SpriteMove

GUICreate("Game Sample", 500, 500, -1, -1)
GUISetBkColor(0x000000)
GUISetState()
$Sprite = SpriteCreate("sprite.jpg", 25, 25, 15, 15)
Sleep(1000)
SpriteMove($Sprite, 200, 15)
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

o... wow, i completely forgot about the GUICtrlSetPos() command..... thanks alot!

Share this post


Link to post
Share on other sites

okay, i had one more question, how would i make it so it MOVES and u can see it MOVE, not just jump top that position....?

Share this post


Link to post
Share on other sites

example:

#include <GuiConstants.au3>

Global $Image, $Width, $Height, $StartX, $StartY
Func SpriteCreate($Image, $Width, $Height, $StartX, $StartY)
 Global $controlID
 $controlID = GUICtrlCreatePic($Image, $StartX, $StartY, $Width, $Height)
 If $controlID Then
  Return $controlID
 Else
  SetError(1)
  Return 0
 EndIf
EndFunc  ;==>SpriteCreate

Func SpriteMove($controlID, $x, $y); move to x and y position
 GUICtrlSetPos($controlID, $x, $y)
EndFunc  ;==>SpriteMove

GUICreate("Game Sample", 500, 500, -1, -1)
GUISetBkColor(0x000000)
GUISetState()
$Sprite = SpriteCreate("sprite.jpg", 25, 25, 15, 15)
For $x = 25 To 200
 SpriteMove($Sprite, $x, 15)
 Sleep ( 10 )
Next
 
While 1
 $msg = GUIGetMsg()
 If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

I get what your doing but im still a little confused...

sry to keep buggin you, but how would i make it move to the position X and Y

like SpriteMove($Sprite, $x, $y) ; moves $Sprite to position x y

???

btw, i really really appreciate your help!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

#include <GuiConstants.au3>

Global $Image, $Width, $Height, $StartX, $StartY
Func SpriteCreate($Image, $Width, $Height, $StartX, $StartY)
    Global $controlID
    $controlID = GUICtrlCreatePic($Image, $StartX, $StartY, $Width, $Height)
    If $controlID Then
        Return $controlID
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc  ;==>SpriteCreate

Func SpriteMove($controlID, $x, $y); move to x and y position
    GUICtrlSetPos($controlID, $x, $y)
EndFunc  ;==>SpriteMove

GUICreate("Game Sample", 500, 500, -1, -1)
GUISetBkColor(0x000000)
GUISetState()
$Sprite = SpriteCreate("sprite.jpg", 25, 25, 15, 15)
$y = 25
For $x = 25 To 200
    SpriteMove($Sprite, $x, $y)
    Sleep ( 10 )
    $y = $y + 1
Next
    
;~ Sleep(1000)
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Hey Chris... FYI... Take a look at your signature, your returning a decimal value but calling it a Hex value in the variable name

While 1
    Local $Mouse = MouseGetPos()
    Local $MouseX = $Mouse[0]
    Local $MouseY = $Mouse[1]
    Local $ColorHex = PixelGetColor($MouseX, $MouseY)
    TrayTip("information", "Mouse X Position: " & $MouseX & @CRLF & "Mouse Y Position: " & $MouseY & @CRLF & "Hex Color: 0x" & Hex($ColorHex, 6), 0)
    Sleep(10)
WEnd
would fix it :o.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Hey Chris... FYI... Take a look at your signature, your returning a decimal value but calling it a Hex value in the variable name

While 1
    Local $Mouse = MouseGetPos()
    Local $MouseX = $Mouse[0]
    Local $MouseY = $Mouse[1]
    Local $ColorHex = PixelGetColor($MouseX, $MouseY)
    TrayTip("information", "Mouse X Position: " & $MouseX & @CRLF & "Mouse Y Position: " & $MouseY & @CRLF & "Hex Color: 0x" & Hex($ColorHex, 6), 0)
    Sleep(10)
WEnd
would fix it :o.
oh, woops. thanks for pointing that out...

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