Sign in to follow this  
Followers 0
Kohr

Any other way to fresh graphic

4 posts in this topic

I am working on a game for a friend and I am trying to making the dice appear to "roll" where they are fast at the beginning and slow to a stop. Everything works fine except the refresh actually refreshes the entire GUI instead of just the control.

To this this effect run the code and hit the "RollDice" button. The button is refreshing along with the other controls.

Does anyone have any tips or advice on how to do this?

Kohr

working example of dice rolling

#region --- include, Opt, Globals, HotKeySet ---
#include <GUIConstants.au3>
#include <Array.au3>

Opt("GUIOnEventMode", 1)

HotKeySet("{END}", "CloseClicked")
#endregion --- include, Opt, Globals, HotKeySet ---
#region --- GUI ---
$GUImain = GUICreate("", 100, 130, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MINIMIZEBOX + $WS_MAXIMIZEBOX)
GUISetBkColor (0xE0FFFF)

$GraphicDice1 = GUICtrlCreateGraphic(10, 10, 40, 40)
GUICtrlSetBkColor($GraphicDice1, 0xffffff)
$GraphicDice2 = GUICtrlCreateGraphic(60, 10, 40, 40)
GUICtrlSetBkColor($GraphicDice2, 0xffffff)

$btnRollDice = GUICtrlCreateButton("RollDice", 10, 60, 70, 20)
GUICtrlSetOnEvent($btnRollDice, "RollDice")

GUISetState(@SW_SHOW, $GUImain)
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseClicked")
#endregion --- GUI ---
While 1
    Sleep(200)
WEnd
#region --- Functions for closing ---
Func CloseClicked()
    Exit
EndFunc   ;==>CloseClicked
#endregion --- Functions for closing ---
Func RollDice()
    For $x = 10 To 22
        Sleep($x)
        $Dice1Value = Random(1, 6, 1)
        $Dice2Value = Random(1, 6, 1)
        Dice(1, $Dice1Value)
        Dice(2, $Dice2Value)
    Next
EndFunc   ;==>RollDice

Func Dice($Dice, $Number)
    $dotsize = 4
    $dicecolor = 0xffffff
    $spotcolor = 0x000000
    If $Dice = 1 Then
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_COLOR, $dicecolor, $dicecolor)
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 20, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 20, 20, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 20, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_COLOR, $spotcolor, $spotcolor)
        Switch $Number
            Case 1
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 20, 20, $dotsize, 0, 360)
            Case 2
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
            Case 3
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 20, 20, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
            Case 4
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
            Case 5
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 20, 20, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
            Case 6
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 20, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 20, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
        EndSwitch
    EndIf
    GUICtrlSetGraphic($GraphicDice1, $GUI_GR_REFRESH)
    If $Dice = 2 Then
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_COLOR, $dicecolor, $dicecolor)
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 20, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 20, 20, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 20, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_COLOR, $spotcolor, $spotcolor)
        Switch $Number
            Case 1
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 20, 20, $dotsize, 0, 360)
            Case 2
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
            Case 3
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 20, 20, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
            Case 4
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
            Case 5
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 20, 20, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
            Case 6
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 20, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 20, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
        EndSwitch
    EndIf
    ;GUICtrlSetGraphic($GraphicDice2,$GUI_GR_REFRESH)
EndFunc   ;==>Dice

Share this post


Link to post
Share on other sites



Download Auto3Lib to get the functions I added and then run this:

CODE
#include <GUIConstants.au3>
#include <Array.au3>
#include <A3LWinAPI.au3>

Opt("GUIOnEventMode", 1)

HotKeySet("{END}", "CloseClicked")
$GUImain = GUICreate("", 100, 130, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MINIMIZEBOX + $WS_MAXIMIZEBOX)
GUISetBkColor (0xE0FFFF)

$GraphicDice1 = GUICtrlCreateGraphic(10, 10, 40, 40)
GUICtrlSetBkColor($GraphicDice1, 0xffffff)
$GraphicDice2 = GUICtrlCreateGraphic(60, 10, 40, 40)
GUICtrlSetBkColor($GraphicDice2, 0xffffff)

$btnRollDice = GUICtrlCreateButton("RollDice", 10, 60, 70, 20)
GUICtrlSetOnEvent($btnRollDice, "RollDice")

GUISetState(@SW_SHOW, $GUImain)
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseClicked")
While 1
  Sleep(200)
WEnd

Func CloseClicked()
  Exit
EndFunc

Func RollDice()
  Local $rRect
  $rRect = _DllStructCreate($RECT)
  _DllStructSetData($rRect, $RECT_TOP   ,  10)
  _DllStructSetData($rRect, $RECT_LEFT  ,  10)
  _DllStructSetData($rRect, $RECT_BOTTOM,  50)
  _DllStructSetData($rRect, $RECT_RIGHT , 100)
  For $x = 10 To 22
   Sleep($x)
   $Dice1Value = Random(1, 6, 1)
   $Dice2Value = Random(1, 6, 1)
   Dice(1, $Dice1Value)
   Dice(2, $Dice2Value)
   _InvalidateRect($GUIMain, $rRect, True)
  Next
EndFunc

Func Dice($Dice, $Number)
    $dotsize = 4
    $dicecolor = 0xffffff
    $spotcolor = 0x000000
    If $Dice = 1 Then
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_COLOR, $dicecolor, $dicecolor)
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 20, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 20, 20, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 20, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice1, $GUI_GR_COLOR, $spotcolor, $spotcolor)
        Switch $Number
            Case 1
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 20, 20, $dotsize, 0, 360)
            Case 2
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
            Case 3
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 20, 20, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
            Case 4
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
            Case 5
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 20, 20, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
            Case 6
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 20, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 20, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice1, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
        EndSwitch
    EndIf
    If $Dice = 2 Then
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_COLOR, $dicecolor, $dicecolor)
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 20, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 20, 20, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 20, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
        GUICtrlSetGraphic($GraphicDice2, $GUI_GR_COLOR, $spotcolor, $spotcolor)
        Switch $Number
            Case 1
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 20, 20, $dotsize, 0, 360)
            Case 2
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
            Case 3
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 20, 20, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
            Case 4
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
            Case 5
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 20, 20, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
            Case 6
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 10, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 20, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 20, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 10, 30, $dotsize, 0, 360)
                GUICtrlSetGraphic($GraphicDice2, $GUI_GR_PIE, 30, 30, $dotsize, 0, 360)
        EndSwitch
    EndIf
EndFunc

Regards,

Paul


Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

Use the codebox and /codebox tags around the code


Auto3Lib: A library of over 1200 functions for AutoIt

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