Sign in to follow this  
Followers 0
Fzz

Flicker Problem with Graphics

3 posts in this topic

Trying to start some stuff with graphics and I'm getting lots of problems with flicker. I saw a nice example using bitblit but I'm not sure if I can apply that to this example. I'm probably just doing something stupid.

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode 
$mainwindow = GUICreate("Bounce", 1000, 730)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$graphic=GuiCtrlCreateGraphic(0, 30, 1000,730)
GUISetState(@SW_SHOW)

$x=20
$y=0
$vx=3
$vy=0

GUICtrlSetGraphic($graphic,$GUI_GR_COLOR, 0x0, 0x00ff00)
GUICtrlSetGraphic($graphic,$GUI_GR_PENSIZE, 1)
GUICtrlSetGraphic($graphic,$GUI_GR_ELLIPSE, $x,$y,11,11)
GUICtrlSetGraphic($graphic,$GUI_GR_REFRESH)

While 1
    Sleep(10)
    MoveBall()
WEnd

Func MoveBall()
    $vy=$vy+1

    If $y+$vy>690 then
        $vy-=3
        $vy*=-1
    EndIf
    If $x+$vx>990 or $x+$vx<0 then
        $vx*=-1
    EndIf
    $x=$x+$vx
    $y=$y+$vy
    if $y>690 then $y=690
    if $y>685 and $x>985 then sleep(1000000)
    GUICtrlSetGraphic($graphic,$GUI_GR_ELLIPSE, $x,$y,11,11)
    GUICtrlSetGraphic($graphic,$GUI_GR_REFRESH)
EndFunc

Func CLOSEClicked()
  Exit
EndFunc

Thanks for looking.

Fz

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Don't use GUICtrlSetGraphic() (in main loop).

Use Win32 API functions instead

or use some DirectX or prospeed or OpenGL stuff from this forum.

EDIT: Look here for links

Edited by Zedna

Share this post


Link to post
Share on other sites

Don't use GUICtrlSetGraphic() (in main loop).

Use Win32 API functions instead

or use some DirectX or prospeed or OpenGL stuff from this forum.

EDIT: Look here for links

So awesome! :) Thank you Zedna!

Used: http://www.autoitscript.com/forum/index.ph...hl=a2d&st=0

#include "A2D.au3";Include the A2D header

$hWnd = GUICreate("Bounce", 1000, 700)
GUISetState()
_A2DStartup("a2d.dll")

if (_A2DFailed(_A2DCreateDevice($hWnd, 1000, 700, $A2DFORMAT_A8R8G8B8))) Then
    MsgBox(0, "Error", "An error occurred while created the A2D Device!")
    _A2DShutdown("a2d.dll")
    Exit
EndIf

$x=20
$y=0
$vx=3
$vy=0
    _A2DClear(0xFFECECEC);Clear the screen to blue. (AARRGGBB)

While(GUIGetMsg() <> -3)
;_A2DClear(0xFFECECEC);Clear the screen to blue. (AARRGGBB)
    _A2DBeginScene()

    _A2DDrawRectangle($x-1, $y-1, 12, 12, 0xFF000000)
    _A2DDrawRectangle($x, $y, 10, 10, 0xFF00FF00)
    
    _A2DEndScene()
    _A2DPresentScene()
    MoveBall()
WEnd

_A2DReleaseDevice()
_A2DShutdown("../a2d.dll")

Func MoveBall()
    $vy=$vy+1

    If $y+$vy>690 then
        $vy-=3
        $vy*=-1
    EndIf
    If $x+$vx>990 or $x+$vx<0 then
        $vx*=-1
    EndIf
    $x=$x+$vx
    $y=$y+$vy
    if $y>690 then $y=690
;if $y>685 and $x>985 then sleep(1000000)
EndFunc

Func CLOSEClicked()
  Exit
EndFunc

Uncomment ;_A2DClear(0xFFECECEC) in loop to remove trails.

Thanks again!

Fz

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