GDI+ Image mit For rumschießen

  • Hey,
    Ich programmiere gerade ein MiniRPG um mich in GDI+ zu trainieren. Mein Problem: Der Zauberer soll einen Partikel rumschießen, aber irgendwie klappts nicht ganz.

    Spoiler anzeigen
    [autoit]

    #include <GuiConstants.au3>
    #include <GdiPlus.au3>;das include
    #include <Misc.au3>

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("_end") ; die Funktion _end am Ende des Scriptes ausführen

    [/autoit] [autoit][/autoit] [autoit]

    $x = 0;x und y deklarieren
    $y = 0

    [/autoit] [autoit][/autoit] [autoit]

    $Gui = GUICreate("Beispiel", 600, 400, 100, 100)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup() ;Gdi starten

    [/autoit] [autoit][/autoit] [autoit]

    $figur = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\char\figur.gif")
    $bk = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\stuff\bg.jpg")
    $particle_red = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\particles\red.gif")
    $height = _GDIPlus_ImageGetHeight($figur)
    $width = _GDIPlus_ImageGetWidth($figur)
    $verhaelnis = $height / $width
    $graphic = _GDIPlus_GraphicsCreateFromHWND($Gui)
    $bitmap = _GDIPlus_BitmapCreateFromGraphics(600, 400, $graphic)
    $buffer = _GDIPlus_ImageGetGraphicsContext($bitmap)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    _GDIPlus_GraphicsDrawImageRect($buffer, $bk, 0, 0, 600, 400)
    _GDIPlus_GraphicsDrawImageRect($buffer, $figur, $x, $y, 40, 40 * $verhaelnis)
    _GDIPlus_GraphicsDrawImage($graphic, $bitmap, 0, 0)
    Sleep(30)
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    Select
    Case _IsPressed(25) And Not $x <= 0; ------------- geändert -------------
    $x -= 5
    Case _IsPressed(26) And Not $y <= 0; ------------- geändert -------------
    $y -= 5
    Case _IsPressed(27) And $x <= 555; ------------- geändert -------------
    $x += 5
    Case _IsPressed(28) And $y <= 355 ; ------------- geändert -------------
    $y += 5
    Case _IsPressed(20)
    For $i=$x To $x + 50
    _GDIPlus_GraphicsDrawImageRect($buffer, $particle_red, $i, 50, 15, 15)
    Next
    EndSelect
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _end();die Exit funktion
    _GDIPlus_GraphicsDispose($graphic);Grafik Objekt freigeben
    _GDIPlus_GraphicsDispose($buffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_ImageDispose($figur);Bild Objekt 1 freigeben
    _GDIPlus_ImageDispose($bk);Bild Objekt 2 freigeben
    _GDIPlus_ImageDispose($particle_red)
    _GDIPlus_Shutdown();Ressourcen freigeben
    EndFunc ;==>_end

    [/autoit]

    Allerdings kommt nichts wenn ich Space drücke. Weiß jemand wie ich das am besten umsetze?

  • Spoiler anzeigen
    [autoit]

    #include <GuiConstants.au3>
    #include <GdiPlus.au3>;das include
    #include <Misc.au3>

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("_end") ; die Funktion _end am Ende des Scriptes ausführen

    [/autoit] [autoit][/autoit] [autoit]

    $x = 0;x und y deklarieren
    $y = 0

    [/autoit] [autoit][/autoit] [autoit]

    $Gui = GUICreate("Beispiel", 600, 400, 100, 100)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup() ;Gdi starten

    [/autoit] [autoit][/autoit] [autoit]

    $figur = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\char\figur.gif")
    $bk = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\stuff\bg.jpg")
    $particle_red = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\particles\red.gif")
    $height = _GDIPlus_ImageGetHeight($figur)
    $width = _GDIPlus_ImageGetWidth($figur)
    $verhaelnis = $height / $width
    $graphic = _GDIPlus_GraphicsCreateFromHWND($Gui)
    $bitmap = _GDIPlus_BitmapCreateFromGraphics(600, 400, $graphic)
    $buffer = _GDIPlus_ImageGetGraphicsContext($bitmap)

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg (0x000F, "WM_PAINT") ; <===========================================

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    _GDIPlus_GraphicsClear ($buffer) ; <==========================================
    _GDIPlus_GraphicsDrawImageRect($buffer, $bk, 0, 0, 600, 400)
    _GDIPlus_GraphicsDrawImageRect($buffer, $figur, $x, $y, 40, 40 * $verhaelnis)
    _GDIPlus_GraphicsDrawImage($graphic, $bitmap, 0, 0)
    Sleep(30)
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    Select
    Case _IsPressed(25) And Not $x <= 0; ------------- geändert -------------
    $x -= 5
    Case _IsPressed(26) And Not $y <= 0; ------------- geändert -------------
    $y -= 5
    Case _IsPressed(27) And $x <= 555; ------------- geändert -------------
    $x += 5
    Case _IsPressed(28) And $y <= 355 ; ------------- geändert -------------
    $y += 5
    Case _IsPressed(20)
    For $i=$x To $x + 50
    _GDIPlus_GraphicsDrawImageRect($buffer, $particle_red, $i, 50, 15, 15)
    _WinAPI_RedrawWindow ($Gui, 0, 0, $RDW_INTERNALPAINT) ; <==============
    Next
    EndSelect
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func WM_PAINT ()
    _GDIPlus_GraphicsDrawImageRect ($graphic, $bitmap, 0, 0, 600, 400)
    EndFunc ;==> WM_PAINT

    [/autoit] [autoit][/autoit] [autoit]

    Func _end();die Exit funktion
    _GDIPlus_GraphicsDispose($graphic);Grafik Objekt freigeben
    _GDIPlus_GraphicsDispose($buffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_ImageDispose($figur);Bild Objekt 1 freigeben
    _GDIPlus_ImageDispose($bk);Bild Objekt 2 freigeben
    _GDIPlus_ImageDispose($particle_red)
    _GDIPlus_Shutdown();Ressourcen freigeben
    EndFunc ;==>_end

    [/autoit]
  • $RDW_INTERNALPAINT
    Das zeigt es als nicht deklarierte Variable an.
    Mit #include <WinApi.au3> lässt es sich auch nicht beheben.

    €: Hat sich erledigt(#include WindowsConstants)