Jump to content

Animated "PacMan" in a GUI


Chattah
 Share

Recommended Posts

NOTE: Originally Posted in General Support Forum but reposted here because this is the forum it really belongs under.

Hey guys I've been playing with AutoIT now for about a month using it mostly to automate some boring tasks at work. Well recently I have decided to mess around with other aspects of it and here lies my issue.

I'm trying to create an animated pacman that will eventually run around the screen and eat things. I have been unable so far to either reduce or eliminate the flicker that happens when my pac man opens and closes his mouth. There are also some pixels that aren't being cleared out when the mouth opens back up but I couldn't figure that part out either.

Any help would be appreciated.

Thanks!!

CODE
#include <GUIConstants.au3>

HotKeySet("{ESC}", "_zExitScript")

GUICreate("Renee1", 600, 600, -1, -1, BitOR($WS_SYSMENU,$WS_POPUPWINDOW,$WS_BORDER,$GUI_ONTOP), $WS_EX_STATICEDGE+$WS_EX_TOPMOST)

GUISetBkColor(0x000000)

$pac_mouth_size = 270; This is the size of the mouth

$pac_mouth_angle = 30; This is the angle the mouth starts at reduce this for proper effect

Do

GUISetState(@SW_SHOW)

Sleep(100)

GuiCtrlCreateGraphic(220, 10)

GUICtrlSetGraphic(-1,$GUI_GR_COLOR, 0, 0xFFFF00)

GUICtrlSetGraphic(-1,$GUI_GR_PIE, 50,50, 30,$pac_mouth_angle,$pac_mouth_size)

GUICtrlSetState(-1, $GUI_GR_REFRESH)

$pac_mouth_size = $pac_mouth_size + 4

$pac_mouth_angle = $pac_mouth_angle - 2

Until $pac_mouth_size >= 350

Do

GUISetState(@SW_SHOW)

Sleep(100)

GuiCtrlCreateGraphic(220, 10)

GUICtrlSetGraphic(-1,$GUI_GR_COLOR, 0, 0xFFFF00)

GUICtrlSetGraphic(-1,$GUI_GR_PIE, 50,50, 30,$pac_mouth_angle,$pac_mouth_size)

GUICtrlSetState(-1, $GUI_GR_REFRESH)

$pac_mouth_size = $pac_mouth_size - 4

$pac_mouth_angle = $pac_mouth_angle + 2

Until $pac_mouth_size <= 270

While 1

Sleep(100)

WEnd

Func _zExitScript()

Exit

EndFunc

Link to comment
Share on other sites

Wel.....

I gave it a try, with no luck

I tried to make the circle yellow and only make the mouth move ( in black ) Then I was hoping that only the black mouth might have a slight flicker... not the entire yellow packman...

didn't work

( reset to yellow)

#include <GUIConstants.au3>

HotKeySet("{ESC}", "_zExitScript")

Global $pac_mouth_size = 90; This is the size of the mouth
Global $pac_mouth_angle = -45; This is the angle the mouth starts at reduce this for proper effect

$GUI = GUICreate("Renee1", 600, 600, -1, -1, BitOR($WS_SYSMENU, $WS_POPUPWINDOW, $WS_BORDER, $GUI_ONTOP), $WS_EX_STATICEDGE + $WS_EX_TOPMOST)
GUISetBkColor(0x000000)

$Graphic = GUICtrlCreateGraphic(220, 10)
GUICtrlSetGraphic($Graphic, $GUI_GR_COLOR, 0, 0xFFFF00)
GUICtrlSetGraphic($Graphic, $GUI_GR_PIE, 50, 50, 30, 0, 360)

$Graphic1=GuiCtrlCreateGraphic(220, 10)
GUICtrlSetGraphic($Graphic1,$GUI_GR_COLOR, 0xFFFF00, 0xFFFF00)
GUICtrlSetGraphic($Graphic1,$GUI_GR_PIE, 50, 50, 30, -45, 90)

GUISetState(@SW_SHOW)



While 1
    
    Sleep(100)
    Open()
    
    Sleep(100)
    Close()
WEnd

Func Open()
    Do
        Sleep(50)
        GUICtrlSetGraphic($Graphic1, $GUI_GR_COLOR, 0, 0xFFFF00)
        GUICtrlSetGraphic($Graphic1, $GUI_GR_PIE, 50, 50, 30, $pac_mouth_angle, $pac_mouth_size)
        GUICtrlSetState($Graphic1, $GUI_GR_REFRESH)
        $pac_mouth_size = $pac_mouth_size  + 4
        $pac_mouth_angle = $pac_mouth_angle - 2
    Until $pac_mouth_size >= 90
EndFunc   ;==>Open

Func Close()
    Do
        Sleep(50)
        GUICtrlSetGraphic($Graphic1, $GUI_GR_COLOR, 0, 0xFFFF00)
        GUICtrlSetGraphic($Graphic1, $GUI_GR_PIE, 50, 50, 30, $pac_mouth_angle, $pac_mouth_size)
        GUICtrlSetState($Graphic1, $GUI_GR_REFRESH)
        $pac_mouth_size = $pac_mouth_size - 4
        $pac_mouth_angle = $pac_mouth_angle + 2
    Until $pac_mouth_size <= 2
EndFunc   ;==>Close

Func _zExitScript()
    Exit
EndFunc   ;==>_zExitScript

8)

NEWHeader1.png

Link to comment
Share on other sites

I don't think you can remove that flickering completely without making it too slow.

This one comes pretty close:

#include <GUIConstants.au3>

HotKeySet("{ESC}", "_zExitScript")

GUICreate("Renee1", 600, 600, -1, -1, BitOR($WS_SYSMENU, $WS_POPUPWINDOW, $WS_BORDER, $GUI_ONTOP), $WS_EX_STATICEDGE + $WS_EX_TOPMOST)
GUISetBkColor(0x000000)
GUISetState(@SW_SHOW)

While 1
;open
    GUICtrlCreateGraphic(220, 10)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0xFFFF00)
        GUICtrlSetGraphic(-1, $GUI_GR_PIE, 50, 50, 30, 30, 290)
        GUICtrlSetState(-1, $GUI_GR_REFRESH)
    Sleep(250)
    GuiCtrlDelete(-1)
;half-open
    GUICtrlCreateGraphic(220, 10)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0xFFFF00)
        GUICtrlSetGraphic(-1, $GUI_GR_PIE, 50, 50, 30, 15, 325)
        GUICtrlSetState(-1, $GUI_GR_REFRESH)
    Sleep(250)
    GuiCtrlDelete(-1)
;closed
    GUICtrlCreateGraphic(220, 10)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0xFFFF00)
        GUICtrlSetGraphic(-1, $GUI_GR_PIE, 50, 50, 30, 1, 355)
        GUICtrlSetState(-1, $GUI_GR_REFRESH)
    Sleep(250)
    GuiCtrlDelete(-1)
;half-open
    GUICtrlCreateGraphic(220, 10)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0xFFFF00)
        GUICtrlSetGraphic(-1, $GUI_GR_PIE, 50, 50, 30, 15, 325)
        GUICtrlSetState(-1, $GUI_GR_REFRESH)
    Sleep(250)
    GuiCtrlDelete(-1)
WEnd

Func _zExitScript()
    Exit
EndFunc   ;==>_zExitScript

Anyway, lets consider you do manage to solve this control update problem one way or another. That's not the only thing you want to do, right? You need to move it around, or if it's a game, let the user move it around. This animation and the moving has to be happening simultaneously. How are you gonna solve that in current implementation?

I don't think GUICtrlCreateGraphic() is up to the task.

You're better off getting the pacman animation into gif or avi or flash (there are available on the net, or you can make it yourself), creating appropriate control to hold it, which you can easily move around and let the system handle the animation part.

Or maybe that OpenGl plugin, as it was suggested.

Edited by Siao

"be smart, drink your wine"

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