Jump to content

GDIplus Graphics problem


Recommended Posts

I've had a very bothersome problem while trying to make a GDIplus program. Ideally it would create a person(stick figure) who can walk around, jump, and sort of explore. It would be like a 2D side-scrolling game. But my problem is that when I use one of the arrow keys to move the position of the person, the program didn't delete the original person. So then I have like hundreds of people. Here's two versions of the script, but neither of them work, any help provided will be much appreciated, thank you.

AutoITphil

#include <WindowsConstants.au3>
#include <WinAPI.au3>
#Include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <misc.au3>

Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)

Global $hGraphic, $hGUI, $hPen, $leg1X1, $leg1Y1, $leg1X2, $leg1Y2, $leg2X1, $leg2Y1, $leg2X2, $leg2Y2, $bodyX1, $bodyY1, $bodyX2, $bodyY2, $w, $h, $hWnd
Global $arm1X1, $arm1Y1, $arm1X2, $arm1Y2, $arm2X1, $arm2Y1, $arm2X2, $arm2Y2, $headX, $headY, $headWID, $headHEI, $redraw = 0, $hBitmap, $hBuffer
$h = 0 ;@DesktopHeight
$w = 0 ;@DesktopWidth
main()

func main()

    Local $msg = 0
    $leg1X1 = @desktopwidth/2
    $leg1Y1 = @desktopheight-300
    $leg1X2 = $leg1X1 - 30
    $leg1y2 = $leg1Y1 + 80
    $leg2X1 = $leg1X1
    $leg2Y1 = $leg1Y1
    $leg2X2 = $leg2x1 + 30
    $leg2Y2 = $leg2Y1 + 80
    $bodyX1 = $leg1X1
    $bodyY1 = $leg1Y1
    $bodyX2 = $leg1X1
    $bodyY2 = $leg1Y1 - 100
    $arm1X1 = $leg1X1
    $arm1Y1 = $bodyY2
    $arm1X2 = $leg1X1 - 75
    $arm1Y2 = $arm1Y1 + 25
    $arm2X1 = $leg1X1
    $arm2Y1 = $arm1Y1
    $arm2X2 = $leg1X1 + 75
    $arm2Y2 = $arm1Y1 + 25
    $headX  = $bodyX2 - 20
    $headY  = $bodyY2 - 40
    $headWID= 40
    $headHEI= 40

    $hGUI = GUICreate("Game",@DesktopWidth,@DesktopHeight)
    GUISetBkColor(0xFF0000) ;i like red backgrounds
    GUISetState()

    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    $hPen = _GDIPlus_PenCreate()
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    AdlibRegister("_ReDraw", 20)
    GUIRegisterMsg(0x000F, "_ReFresh") ;$WM_PAINT = 0x000F
    OnAutoItExitRegister("_Exit")

    _GDIPlus_GraphicsDrawLine($hGraphic, $leg1X1, $leg1Y1, $leg1X2, $leg1Y2, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $leg2X1, $leg2Y1, $leg2X2, $leg2Y2, $hPen)
    _GDIPlus_GraphicsDrawLine($hgraphic, $bodyX1, $bodyY1, $bodyX2, $bodyY2, $hPen)
    _GDIPlus_GraphicsDrawLine($hgraphic, $arm1X1, $arm1Y1, $arm1X2, $arm1Y2, $hPen)
    _GDIPlus_GraphicsDrawLine($hgraphic, $arm2X1, $arm2Y1, $arm2X2, $arm2Y2, $hPen)
    _GDIPlus_GraphicsDrawEllipse($hgraphic, $headX, $headY, $headWID, $headHEI, $hPen)

    While 1

        if _IsPressed("45") then exit

        if _IsPressed("25") Then ;left arrow
            $leg1X1 -= 1
            $leg1X2 -= 1
            $leg2x1 -= 1
            $leg2X2 -= 1
            $bodyX1 -= 1
            $bodyX2 -= 1
            $arm1X1 -= 1
            $arm1X2 -= 1
            $arm2X1 -= 1
            $arm2X2 -= 1
            $headX  -= 1
            $redraw = 1
            sleep(7)
        EndIf
        if _IsPressed("26") Then ;up arrow
            $leg1Y1 -= 1
            $leg1Y2 -= 1
            $leg2Y1 -= 1
            $leg2Y2 -= 1
            $bodyY1 -= 1
            $bodyY2 -= 1
            $arm1Y1 -= 1
            $arm1Y2 -= 1
            $arm2Y1 -= 1
            $arm2Y2 -= 1
            $headY  -= 1
            $redraw = 1
            sleep(7)
        EndIf
        if _IsPressed("27") Then ;right arrow
            $leg1X1 += 1
            $leg1X2 += 1
            $leg2x1 += 1
            $leg2X2 += 1
            $bodyX1 += 1
            $bodyX2 += 1
            $arm1X1 += 1
            $arm1X2 += 1
            $arm2X1 += 1
            $arm2X2 += 1
            $headX  += 1
            $redraw = 1
            sleep(7)
        EndIf
        if _IsPressed("28") Then ; down arrow
            $leg1Y1 += 1
            $leg1Y2 += 1
            $leg2Y1 += 1
            $leg2Y2 += 1
            $bodyY1 += 1
            $bodyY2 += 1
            $arm1Y1 += 1
            $arm1Y2 += 1
            $arm2Y1 += 1
            $arm2Y2 += 1
            $headY  += 1
            $redraw = 1
            sleep(7)
        EndIf
    WEnd

;~     _GDIPlus_PenDispose ($hPen)
;~     _GDIPlus_GraphicsDispose ($hGraphic)
;~     _GDIPlus_Shutdown ()

EndFunc

Func _ReDraw()
    _GDIPlus_GraphicsClear($hBuffer, 0xFF0000)
    If $redraw Then
        _GDIPlus_GraphicsDrawLine($hGraphic, $leg1X1, $leg1Y1, $leg1X2, $leg1Y2, $hPen)
        _GDIPlus_GraphicsDrawLine($hGraphic, $leg2X1, $leg2Y1, $leg2X2, $leg2Y2, $hPen)
        _GDIPlus_GraphicsDrawLine($hgraphic, $bodyX1, $bodyY1, $bodyX2, $bodyY2, $hPen)
        _GDIPlus_GraphicsDrawLine($hgraphic, $arm1X1, $arm1Y1, $arm1X2, $arm1Y2, $hPen)
        _GDIPlus_GraphicsDrawLine($hgraphic, $arm2X1, $arm2Y1, $arm2X2, $arm2Y2, $hPen)
        _GDIPlus_GraphicsDrawEllipse($hgraphic, $headX, $headY, $headWID, $headHEI, $hPen)
        $redraw = 0
    EndIf
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 0, 0)
EndFunc

Func _ReFresh()
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 0, 0)
    Return "GUI_RUNDEFMSG"
EndFunc

Func _Exit()
    GUIRegisterMsg(0x000F, "")
    AdlibUnRegister("_ReDraw")
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    GUIDelete($hWnd)
    Exit
EndFunc

and the other

#include <WindowsConstants.au3>
#include <WinAPI.au3>
#Include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <misc.au3>

Opt('MustDeclareVars', 1)

func main()
    local $hGraphic, $hGUI, $hPen, $leg1X1, $leg1Y1, $leg1X2, $leg1Y2, $leg2X1, $leg2Y1, $leg2X2, $leg2Y2, $bodyX1, $bodyY1, $bodyX2, $bodyY2
    local $arm1X1, $arm1Y1, $arm1X2, $arm1Y2, $arm2X1, $arm2Y1, $arm2X2, $arm2Y2, $headX, $headY, $headWID, $headHEI
    $leg1X1 = @desktopwidth/2
    $leg1Y1 = @desktopheight-300
    $leg1X2 = $leg1X1 - 30
    $leg1y2 = $leg1Y1 + 80
    $leg2X1 = $leg1X1
    $leg2Y1 = $leg1Y1
    $leg2X2 = $leg2x1 + 30
    $leg2Y2 = $leg2Y1 + 80
    $bodyX1 = $leg1X1
    $bodyY1 = $leg1Y1
    $bodyX2 = $leg1X1
    $bodyY2 = $leg1Y1 - 100
    $arm1X1 = $leg1X1
    $arm1Y1 = $bodyY2
    $arm1X2 = $leg1X1 - 75
    $arm1Y2 = $arm1Y1 + 25
    $arm2X1 = $leg1X1
    $arm2Y1 = $arm1Y1
    $arm2X2 = $leg1X1 + 75
    $arm2Y2 = $arm1Y1 + 25
    $headX  = $bodyX2 - 20
    $headY  = $bodyY2 - 40
    $headWID= 40
    $headHEI= 40



    $hGUI = GUICreate("Game",@DesktopWidth,@DesktopHeight)
    GUISetBkColor(0xFF0000) ;i like red backgrounds
    GUISetState()

    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hPen = _GDIPlus_PenCreate()

Do
while 1
  if _IsPressed("45") then exit
    _GDIPlus_GraphicsDrawLine($hGraphic, $leg1X1, $leg1Y1, $leg1X2, $leg1Y2, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $leg2X1, $leg2Y1, $leg2X2, $leg2Y2, $hPen)
    _GDIPlus_GraphicsDrawLine($hgraphic, $bodyX1, $bodyY1, $bodyX2, $bodyY2, $hPen)
    _GDIPlus_GraphicsDrawLine($hgraphic, $arm1X1, $arm1Y1, $arm1X2, $arm1Y2, $hPen)
    _GDIPlus_GraphicsDrawLine($hgraphic, $arm2X1, $arm2Y1, $arm2X2, $arm2Y2, $hPen)
    _GDIPlus_GraphicsDrawEllipse($hgraphic, $headX, $headY, $headWID, $headHEI, $hPen)
    if _IsPressed("25") Then ;left arrow
        $leg1X1 -= 1
        $leg1X2 -= 1
        $leg2x1 -= 1
        $leg2X2 -= 1
        $bodyX1 -= 1
        $bodyX2 -= 1
        $arm1X1 -= 1
        $arm1X2 -= 1
        $arm2X1 -= 1
        $arm2X2 -= 1
        $headX  -= 1

        sleep(7)
    EndIf
    if _IsPressed("26") Then ;up arrow
        $leg1Y1 -= 1
        $leg1Y2 -= 1
        $leg2Y1 -= 1
        $leg2Y2 -= 1
        $bodyY1 -= 1
        $bodyY2 -= 1
        $arm1Y1 -= 1
        $arm1Y2 -= 1
        $arm2Y1 -= 1
        $arm2Y2 -= 1
        $headY  -= 1
        sleep(7)
    EndIf
    if _IsPressed("27") Then ;right arrow
        $leg1X1 += 1
        $leg1X2 += 1
        $leg2x1 += 1
        $leg2X2 += 1
        $bodyX1 += 1
        $bodyX2 += 1
        $arm1X1 += 1
        $arm1X2 += 1
        $arm2X1 += 1
        $arm2X2 += 1
        $headX  += 1
        sleep(7)
    EndIf
    if _IsPressed("28") Then ; down arrow
        $leg1Y1 += 1
        $leg1Y2 += 1
        $leg2Y1 += 1
        $leg2Y2 += 1
        $bodyY1 += 1
        $bodyY2 += 1
        $arm1Y1 += 1
        $arm1Y2 += 1
        $arm2Y1 += 1
        $arm2Y2 += 1
        $headY  += 1
        sleep(7)
    EndIf
WEnd
Until GUIGetMsg() = $GUI_EVENT_CLOSE

    _GDIPlus_PenDispose ($hPen)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_Shutdown ()

endFunc

main()
Link to comment
Share on other sites

Like so?

#include <WindowsConstants.au3>
#include <WinAPI.au3>
#Include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <misc.au3>

Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)

Global $hGraphic, $hGUI, $hPen, $leg1X1, $leg1Y1, $leg1X2, $leg1Y2, $leg2X1, $leg2Y1, $leg2X2, $leg2Y2, $bodyX1, $bodyY1, $bodyX2, $bodyY2, $w, $h, $hWnd
Global $arm1X1, $arm1Y1, $arm1X2, $arm1Y2, $arm2X1, $arm2Y1, $arm2X2, $arm2Y2, $headX, $headY, $headWID, $headHEI, $redraw = 0, $hBitmap, $hBuffer
$h = 0 ;@DesktopHeight
$w = 0 ;@DesktopWidth
main()

func main()

    Local $msg = 0
    $leg1X1 = @desktopwidth/2
    $leg1Y1 = @desktopheight-300
    $leg1X2 = $leg1X1 - 30
    $leg1y2 = $leg1Y1 + 80
    $leg2X1 = $leg1X1
    $leg2Y1 = $leg1Y1
    $leg2X2 = $leg2x1 + 30
    $leg2Y2 = $leg2Y1 + 80
    $bodyX1 = $leg1X1
    $bodyY1 = $leg1Y1
    $bodyX2 = $leg1X1
    $bodyY2 = $leg1Y1 - 100
    $arm1X1 = $leg1X1
    $arm1Y1 = $bodyY2
    $arm1X2 = $leg1X1 - 75
    $arm1Y2 = $arm1Y1 + 25
    $arm2X1 = $leg1X1
    $arm2Y1 = $arm1Y1
    $arm2X2 = $leg1X1 + 75
    $arm2Y2 = $arm1Y1 + 25
    $headX  = $bodyX2 - 20
    $headY  = $bodyY2 - 40
    $headWID= 40
    $headHEI= 40

    $hGUI = GUICreate("Game",@DesktopWidth,@DesktopHeight)
    GUISetBkColor(0xFF0000) ;i like red backgrounds
    GUISetState()

    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    $hPen = _GDIPlus_PenCreate()
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
;~     AdlibRegister("_ReDraw", 20)
    GUIRegisterMsg(0x000F, "_ReFresh") ;$WM_PAINT = 0x000F
    OnAutoItExitRegister("_Exit")

    _GDIPlus_GraphicsDrawLine($hGraphic, $leg1X1, $leg1Y1, $leg1X2, $leg1Y2, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $leg2X1, $leg2Y1, $leg2X2, $leg2Y2, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $bodyX1, $bodyY1, $bodyX2, $bodyY2, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $arm1X1, $arm1Y1, $arm1X2, $arm1Y2, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $arm2X1, $arm2Y1, $arm2X2, $arm2Y2, $hPen)
    _GDIPlus_GraphicsDrawEllipse($hGraphic, $headX, $headY, $headWID, $headHEI, $hPen)

    While 1

        if _IsPressed("45") then exit

        if _IsPressed("25") Then ;left arrow
            _redraw ()
            $leg1X1 -= 1
            $leg1X2 -= 1
            $leg2x1 -= 1
            $leg2X2 -= 1
            $bodyX1 -= 1
            $bodyX2 -= 1
            $arm1X1 -= 1
            $arm1X2 -= 1
            $arm2X1 -= 1
            $arm2X2 -= 1
            $headX  -= 1
            $redraw = 1
            sleep(7)
        EndIf
        if _IsPressed("26") Then ;up arrow
            _redraw ()
            $leg1Y1 -= 1
            $leg1Y2 -= 1
            $leg2Y1 -= 1
            $leg2Y2 -= 1
            $bodyY1 -= 1
            $bodyY2 -= 1
            $arm1Y1 -= 1
            $arm1Y2 -= 1
            $arm2Y1 -= 1
            $arm2Y2 -= 1
            $headY  -= 1
            $redraw = 1
            sleep(7)
        EndIf
        if _IsPressed("27") Then ;right arrow
            _redraw ()
            $leg1X1 += 1
            $leg1X2 += 1
            $leg2x1 += 1
            $leg2X2 += 1
            $bodyX1 += 1
            $bodyX2 += 1
            $arm1X1 += 1
            $arm1X2 += 1
            $arm2X1 += 1
            $arm2X2 += 1
            $headX  += 1
            $redraw = 1
            sleep(7)
        EndIf
        if _IsPressed("28") Then ; down arrow
            _redraw ()
            $leg1Y1 += 1
            $leg1Y2 += 1
            $leg2Y1 += 1
            $leg2Y2 += 1
            $bodyY1 += 1
            $bodyY2 += 1
            $arm1Y1 += 1
            $arm1Y2 += 1
            $arm2Y1 += 1
            $arm2Y2 += 1
            $headY  += 1
            $redraw = 1
            sleep(7)
        EndIf
    WEnd

;~     _GDIPlus_PenDispose ($hPen)
;~     _GDIPlus_GraphicsDispose ($hGraphic)
;~     _GDIPlus_Shutdown ()

EndFunc

Func _ReDraw()
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsClear($hGraphic , 0xFFFF0000)
    If $redraw = 1 Then
        _GDIPlus_GraphicsDrawLine($hGraphic, $leg1X1, $leg1Y1, $leg1X2, $leg1Y2, $hPen)
        _GDIPlus_GraphicsDrawLine($hGraphic, $leg2X1, $leg2Y1, $leg2X2, $leg2Y2, $hPen)
        _GDIPlus_GraphicsDrawLine($hgraphic, $bodyX1, $bodyY1, $bodyX2, $bodyY2, $hPen)
        _GDIPlus_GraphicsDrawLine($hgraphic, $arm1X1, $arm1Y1, $arm1X2, $arm1Y2, $hPen)
        _GDIPlus_GraphicsDrawLine($hgraphic, $arm2X1, $arm2Y1, $arm2X2, $arm2Y2, $hPen)
        _GDIPlus_GraphicsDrawEllipse($hgraphic, $headX, $headY, $headWID, $headHEI, $hPen)
        $redraw = 0
    EndIf
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 0, 0)
EndFunc

Func _ReFresh()
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 0, 0)
    Return "GUI_RUNDEFMSG"
EndFunc

Func _Exit()
    GUIRegisterMsg(0x000F, "")
    AdlibUnRegister("_ReDraw")
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    GUIDelete($hWnd)
    Exit
EndFunc

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Here some small modifications.

#include <WindowsConstants.au3>
#include <WinAPI.au3>
#Include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <misc.au3>

Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)

Global $hGraphic, $hGUI, $hPen, $leg1X1, $leg1Y1, $leg1X2, $leg1Y2, $leg2X1, $leg2Y1, $leg2X2, $leg2Y2, $bodyX1, $bodyY1, $bodyX2, $bodyY2, $w, $h, $hWnd
Global $arm1X1, $arm1Y1, $arm1X2, $arm1Y2, $arm2X1, $arm2Y1, $arm2X2, $arm2Y2, $headX, $headY, $headWID, $headHEI, $redraw = 0, $hBitmap, $hBuffer
$h = @DesktopHeight
$w = @DesktopWidth
main()

func main()

    Local $msg = 0
    $leg1X1 = $w/2
    $leg1Y1 = $h-300
    $leg1X2 = $leg1X1 - 30
    $leg1y2 = $leg1Y1 + 80
    $leg2X1 = $leg1X1
    $leg2Y1 = $leg1Y1
    $leg2X2 = $leg2x1 + 30
    $leg2Y2 = $leg2Y1 + 80
    $bodyX1 = $leg1X1
    $bodyY1 = $leg1Y1
    $bodyX2 = $leg1X1
    $bodyY2 = $leg1Y1 - 100
    $arm1X1 = $leg1X1
    $arm1Y1 = $bodyY2
    $arm1X2 = $leg1X1 - 75
    $arm1Y2 = $arm1Y1 + 25
    $arm2X1 = $leg1X1
    $arm2Y1 = $arm1Y1
    $arm2X2 = $leg1X1 + 75
    $arm2Y2 = $arm1Y1 + 25
    $headX  = $bodyX2 - 20
    $headY  = $bodyY2 - 40
    $headWID= 40
    $headHEI= 40

    $hGUI = GUICreate("Game",$w, $h, -1, -1)
    GUISetBkColor(0xFF0000) ;i like red backgrounds
    GUISetState()

    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    $hPen = _GDIPlus_PenCreate()
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
;~     AdlibRegister("_ReDraw", 20)
;~     GUIRegisterMsg(0x000F, "_ReFresh") ;$WM_PAINT = 0x000F
    OnAutoItExitRegister("_Exit")

    _GDIPlus_GraphicsDrawLine($hBuffer, $leg1X1, $leg1Y1, $leg1X2, $leg1Y2, $hPen)
    _GDIPlus_GraphicsDrawLine($hBuffer, $leg2X1, $leg2Y1, $leg2X2, $leg2Y2, $hPen)
    _GDIPlus_GraphicsDrawLine($hBuffer, $bodyX1, $bodyY1, $bodyX2, $bodyY2, $hPen)
    _GDIPlus_GraphicsDrawLine($hBuffer, $arm1X1, $arm1Y1, $arm1X2, $arm1Y2, $hPen)
    _GDIPlus_GraphicsDrawLine($hBuffer, $arm2X1, $arm2Y1, $arm2X2, $arm2Y2, $hPen)
    _GDIPlus_GraphicsDrawEllipse($hBuffer, $headX, $headY, $headWID, $headHEI, $hPen)

    $redraw = 1
    _redraw ()

    While 1

        if _IsPressed("45") then exit

        if _IsPressed("25") Then ;left arrow
            _redraw ()
            $leg1X1 -= 1
            $leg1X2 -= 1
            $leg2x1 -= 1
            $leg2X2 -= 1
            $bodyX1 -= 1
            $bodyX2 -= 1
            $arm1X1 -= 1
            $arm1X2 -= 1
            $arm2X1 -= 1
            $arm2X2 -= 1
            $headX  -= 1
            $redraw = 1
            sleep(7)
        EndIf
        if _IsPressed("26") Then ;up arrow
            _redraw ()
            $leg1Y1 -= 1
            $leg1Y2 -= 1
            $leg2Y1 -= 1
            $leg2Y2 -= 1
            $bodyY1 -= 1
            $bodyY2 -= 1
            $arm1Y1 -= 1
            $arm1Y2 -= 1
            $arm2Y1 -= 1
            $arm2Y2 -= 1
            $headY  -= 1
            $redraw = 1
            sleep(7)
        EndIf
        if _IsPressed("27") Then ;right arrow
            _redraw ()
            $leg1X1 += 1
            $leg1X2 += 1
            $leg2x1 += 1
            $leg2X2 += 1
            $bodyX1 += 1
            $bodyX2 += 1
            $arm1X1 += 1
            $arm1X2 += 1
            $arm2X1 += 1
            $arm2X2 += 1
            $headX  += 1
            $redraw = 1
            sleep(7)
        EndIf
        if _IsPressed("28") Then ; down arrow
            _redraw ()
            $leg1Y1 += 1
            $leg1Y2 += 1
            $leg2Y1 += 1
            $leg2Y2 += 1
            $bodyY1 += 1
            $bodyY2 += 1
            $arm1Y1 += 1
            $arm1Y2 += 1
            $arm2Y1 += 1
            $arm2Y2 += 1
            $headY  += 1
            $redraw = 1
            sleep(7)
        EndIf
    WEnd

EndFunc

Func _ReDraw()
    _GDIPlus_GraphicsClear($hBuffer , 0xFFFF0000)
    If $redraw = 1 Then
        _GDIPlus_GraphicsDrawLine($hBuffer, $leg1X1, $leg1Y1, $leg1X2, $leg1Y2, $hPen)
        _GDIPlus_GraphicsDrawLine($hBuffer, $leg2X1, $leg2Y1, $leg2X2, $leg2Y2, $hPen)
        _GDIPlus_GraphicsDrawLine($hBuffer, $bodyX1, $bodyY1, $bodyX2, $bodyY2, $hPen)
        _GDIPlus_GraphicsDrawLine($hBuffer, $arm1X1, $arm1Y1, $arm1X2, $arm1Y2, $hPen)
        _GDIPlus_GraphicsDrawLine($hBuffer, $arm2X1, $arm2Y1, $arm2X2, $arm2Y2, $hPen)
        _GDIPlus_GraphicsDrawEllipse($hBuffer, $headX, $headY, $headWID, $headHEI, $hPen)
        $redraw = 0
    EndIf
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $w, $h)
EndFunc

Func _ReFresh()
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $w, $h)
    Return "GUI_RUNDEFMSG"
EndFunc

Func _Exit()
    ;GUIRegisterMsg(0x000F, "")
    ;AdlibUnRegister("_ReDraw")
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    GUIDelete($hWnd)
    Exit
EndFunc

You initialized backbuffer but didn't used it.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Hello AutoItphil,

I posted the solution there today. I responded to your PM telling you that I would post the solution in your original topic for public view.

Realm

Edit: However UEZ has much more experience on this level, and his advice in the post above this one is what you should refer to over mine.

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Link to comment
Share on other sites

I appreciate the link, but that was actually another post of mine, I tried that solution and messaged the poster of that solution, but it was to no avail. thank you

You could do something like this using your first example (but changed a bit to suit my approach.).

#include <WindowsConstants.au3>
#include <WinAPI.au3>
#Include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <misc.au3>

Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)

Global $hGraphic, $hGUI, $hPen, $leg1X1, $leg1Y1, $leg1X2, $leg1Y2, $leg2X1, $leg2Y1, $leg2X2, $leg2Y2, $bodyX1, $bodyY1, $bodyX2, $bodyY2, $w, $h, $hWnd
Global $arm1X1, $arm1Y1, $arm1X2, $arm1Y2, $arm2X1, $arm2Y1, $arm2X2, $arm2Y2, $headX, $headY, $headWID, $headHEI, $redraw = 0, $hBitmap, $hBuffer
Global $hEraser, $Xshift = 0, $yshift = 0, $lastXshift=0, $lastYshift=0, $force
$h = 0 ;@DesktopHeight
$w = 0 ;@DesktopWidth
main()

func main()

    Local $msg = 0
    $leg1X1 = @desktopwidth/2
    $leg1Y1 = @desktopheight-300
    $leg1X2 = $leg1X1 - 30
    $leg1y2 = $leg1Y1 + 80
    $leg2X1 = $leg1X1
    $leg2Y1 = $leg1Y1
    $leg2X2 = $leg2x1 + 30
    $leg2Y2 = $leg2Y1 + 80
    $bodyX1 = $leg1X1
    $bodyY1 = $leg1Y1
    $bodyX2 = $leg1X1
    $bodyY2 = $leg1Y1 - 100
    $arm1X1 = $leg1X1
    $arm1Y1 = $bodyY2
    $arm1X2 = $leg1X1 - 75
    $arm1Y2 = $arm1Y1 + 25
    $arm2X1 = $leg1X1
    $arm2Y1 = $arm1Y1
    $arm2X2 = $leg1X1 + 75
    $arm2Y2 = $arm1Y1 + 25
    $headX  = $bodyX2 - 20
    $headY  = $bodyY2 - 40
    $headWID= 40
    $headHEI= 40

    $hGUI = GUICreate("Game",@DesktopWidth,@DesktopHeight)
    GUISetBkColor(0xFF0000) ;i like red backgrounds
    GUISetState()

    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    $hPen = _GDIPlus_PenCreate()
    $hEraser = _GDIPlus_PenCreate(0xFFFF0000)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    AdlibRegister("_ReDraw", 20)
    GUIRegisterMsg(0x000F, "_ReFresh") ;$WM_PAINT = 0x000F
    OnAutoItExitRegister("_Exit")

    _GDIPlus_GraphicsDrawLine($hGraphic, $leg1X1, $leg1Y1, $leg1X2, $leg1Y2, $hPen)
    _GDIPlus_GraphicsDrawLine($hGraphic, $leg2X1, $leg2Y1, $leg2X2, $leg2Y2, $hPen)
    _GDIPlus_GraphicsDrawLine($hgraphic, $bodyX1, $bodyY1, $bodyX2, $bodyY2, $hPen)
    _GDIPlus_GraphicsDrawLine($hgraphic, $arm1X1, $arm1Y1, $arm1X2, $arm1Y2, $hPen)
    _GDIPlus_GraphicsDrawLine($hgraphic, $arm2X1, $arm2Y1, $arm2X2, $arm2Y2, $hPen)
    _GDIPlus_GraphicsDrawEllipse($hgraphic, $headX, $headY, $headWID, $headHEI, $hPen)

    While 1

        if _IsPressed("45") then exit

        if _IsPressed("25") Then ;left arrow
            $Xshift -= 1
            sleep(7)
        EndIf
        if _IsPressed("26") Then ;up arrow
            $yshift -= 1
            sleep(7)
        EndIf
        if _IsPressed("27") Then ;right arrow
            $Xshift += 1
            sleep(7)
        EndIf
        if _IsPressed("28") Then ; down arrow
            $Yshift += 1
            sleep(7)
        EndIf
    WEnd

;~  _GDIPlus_PenDispose ($hPen)
;~  _GDIPlus_GraphicsDispose ($hGraphic)
;~  _GDIPlus_Shutdown ()

EndFunc

Func _ReDraw($force = false)
    Local $apen[2] = [$hEraser,$hpen],$in, $pos[4]=[$lastXshift,$Xshift,$lastYshift,$Yshift]

   if (not $force) and $Xshift = $lastXshift and $Yshift = $lastYshift then Return

    for $in = 0 to 1
    _GDIPlus_GraphicsDrawLine($hGraphic, $leg1X1 + $pos[$in], $leg1Y1 + $pos[$in+2], $leg1X2+ $pos[$in], $leg1Y2 + $pos[$in+2], $apen[$in])
        _GDIPlus_GraphicsDrawLine($hGraphic, $leg2X1+ $pos[$in], $leg2Y1 + $pos[$in+2], $leg2X2+ $pos[$in], $leg2Y2 + $pos[$in+2], $apen[$in])
        _GDIPlus_GraphicsDrawLine($hgraphic, $bodyX1+ $pos[$in], $bodyY1 + $pos[$in+2], $bodyX2+ $pos[$in], $bodyY2 + $pos[$in+2], $apen[$in])
        _GDIPlus_GraphicsDrawLine($hgraphic, $arm1X1+ $pos[$in], $arm1Y1 + $pos[$in+2], $arm1X2+ $pos[$in], $arm1Y2 + $pos[$in+2], $apen[$in])
        _GDIPlus_GraphicsDrawLine($hgraphic, $arm2X1+ $pos[$in], $arm2Y1 + $pos[$in+2], $arm2X2+ $pos[$in], $arm2Y2 + $pos[$in+2], $apen[$in])
        _GDIPlus_GraphicsDrawEllipse($hgraphic, $headX+ $pos[$in], $headY + $pos[$in+2], $headWID, $headHEI, $apen[$in])
    next

    $lastXshift = $Xshift
    $lastYshift = $Yshift
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 0, 0)
EndFunc

Func _ReFresh()
    ConsoleWrite("ikukuhkuhkuh" & @CRLF)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 0, 0)
    _Redraw(true)
    Return "GUI_RUNDEFMSG"
EndFunc

Func _Exit()
    GUIRegisterMsg(0x000F, "")
    AdlibUnRegister("_ReDraw")
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    GUIDelete($hWnd)
    Exit
EndFunc

EDIT: Had seen reply form UEZ so this might be a redundant post.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Here some small modifications.

You initialized backbuffer but didn't used it.

Thanks a lot UEZ

The buffer makes it look immensely better.

and thank you martin as well. I appreciate everyone's help. This a great community of supportive coders.

Edited by AutoITphil
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...