GDI+ GraphicsDrawImage - Bild wird nicht gezeichnet

  • Hey Community,

    ich möchte ein Spiel entwickeln, in dem man herunterfallende Luftballons mit einem Korb einfangen muss.
    Ich weiß, dass es so etwas schon gibt. Der Nebeneffekt soll sein, dass ich GDI+ lerne.
    Ich bin mit den Grundlagen durch [Link entfernt] schon etwas vertraut, aber ich habe nun das Problem, dass ein Ballon nicht gezeichnet wird. Der Hintergrund wird bereits gezeichnet.

    Das Skript:

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    Opt("GUIOnEventMode", 1)
    OnAutoItExitRegister("_Exit")

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

    _GDIPlus_Startup()

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

    Global $iWidth = 500, $iHeight = 600
    Global $iX = 0, $iY = 0
    Global $aPos_Ellipse[4] = [-200, 100, 200, 200]

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

    $hGUI = GUICreate("TrapTheBalloon",$iWidth,$iHeight)
    $hWnd = WinGetHandle("TrapTheBalloon")
    GUISetState()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    ;Erstmal das normale Grafik-Objekt erstellen.
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
    ;Statt uns mit dem normalen Frontbuffer zufrieden zu geben, erstellen wir erstmal eine
    ;Bitmap, mit Bezug auf unser Grafikobjekt.
    $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    ;Nachdem unser Bitmap erstellt ist, holen wir uns den Graphics Context. Dieser
    ;wird von uns verwendet, um darin zu zeichnen
    $red = 0xFF000000 + 0xFF0000
    $green = 0xFF000000 + 0xFF0000
    $blue = 0xFF000000 + 0xFF0000
    $yellow = 0xFF000000 + 0xFF0000
    $pink = 0xFF000000 + 0xFF0000
    Global $hBackground = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\background.png")
    Global $balloon_red = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\balloon_red.png")
    Global $balloon_green = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\balloon_green.png")
    Global $balloon_blue = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\balloon_blue.png")
    Global $balloon_yellow = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\balloon_yellow.png")
    Global $balloon_pink = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\balloon_pink.png")
    GUISetOnEvent(-3, "_Exit")
    GUIRegisterMsg(0x000F, "WM_PAINT")

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

    While 1

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

    _GDIPlus_GraphicsClear($hBackbuffer)
    ; Superradierer benutzen um alten Backbuffer zu löschen
    _GDIPlus_GraphicsDrawRect($hBitmap,50,50,100,150)
    _WinAPI_RedrawWindow($hWnd, 0, 0,$RDW_INTERNALPAINT)
    ; WM_PAINT wird nur aufgerufen, wenn alle Berechnungen fertig sind!
    ; In WM_PAINT wird selbst nichts berechnet, oder gezeichnet. diese Funktion wird nur das
    ; Bitmap-Objekt in das Grafik-Objekt übertragen.
    Sleep(1000)
    WEnd

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

    Func _Exit() ; Clean up resources
    _GDIPlus_GraphicsDispose($hGraphic) ; Grafikobjekt auflösen
    _GDIPlus_BitmapDispose($hBitmap); Bitmap auflösen
    _GDIPlus_ImageDispose($balloon_red); Bild auflösen
    _GDIPlus_ImageDispose($balloon_green); Bild auflösen
    _GDIPlus_ImageDispose($balloon_blue); Bild auflösen
    _GDIPlus_ImageDispose($balloon_yellow); Bild auflösen
    _GDIPlus_ImageDispose($balloon_pink); Bild auflösen
    _GDIPlus_ImageDispose($hBackground); Bild auflösen
    _GDIPlus_Shutdown() ; GDI+ Engine beenden
    Exit
    EndFunc ;==>_Exit

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

    Func WM_PAINT()
    _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hBackground, 0, 0, $iWidth, $iHeight)
    _GDIPlus_GraphicsDrawImage($hBackbuffer, $balloon_red, 50, 50)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, $iX, $iY, $iWidth, $iHeight)
    ; _GDIPlus_GraphicsDrawImageRect() überträgt den Backbuffer in den Frontbuffer.
    ; Der erste Parameter ist unser Frontbuffer (Grafik Objekt).
    ; Der zweite ist unsere Bitmap, welche ja als BackBuffer fungiert.
    ; Darauf folgt der Abschnitt den man übertragen will.
    ; i.d.R. ist es 0, 0 für X und Y koordinaten, und die GUI Breite und Höhe für
    ; Width und Height. Kommt natürlich immer drauf an, wie groß euer Grafikobjekt ist,
    ; und ob ihr den vollen Teil zeichnen wollt.
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_PAINT

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

    Hier der komplette Ordner als Archiv mit Grafiken.

    autoit.de/wcf/attachment/9748/

    Edit Oscar: Bitte keine Links zu Botforen setzen!

  • Wie wärs wenn du erst den Hintergrund zeichnest und dann den roten Ballon?!? ;)

  • Spoiler anzeigen
    [autoit]


    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    Opt("GUIOnEventMode", 1)
    OnAutoItExitRegister("_Exit")

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

    _GDIPlus_Startup()

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

    Global $iWidth = 500, $iHeight = 600
    Global $iX = 0, $iY = 0
    $hGUI = GUICreate("TrapTheBalloon",$iWidth,$iHeight)
    $hWnd = WinGetHandle("TrapTheBalloon")
    GUISetState()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    ;Erstmal das normale Grafik-Objekt erstellen.
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
    ;Statt uns mit dem normalen Frontbuffer zufrieden zu geben, erstellen wir erstmal eine
    ;Bitmap, mit Bezug auf unser Grafikobjekt.
    $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    ;Nachdem unser Bitmap erstellt ist, holen wir uns den Graphics Context. Dieser
    ;wird von uns verwendet, um darin zu zeichnen
    $red = 0xFFFF0000
    $green = 0xFF00FF00
    $blue = 0xFF0000FF
    $yellow = 0xFFFFFF00
    $pink = 0xFFFF1493
    Global $hBackground = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\background.png")
    Global $balloon_red = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\ballon_red.png")
    Global $balloon_green = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\ballon_green.png")
    Global $balloon_blue = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\ballon_blue.png")
    Global $balloon_yellow = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\ballon_yellow.png")
    Global $balloon_pink = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\ballon_pink.png")
    _GDIPlus_GraphicsDrawEllipse($hBitmap,50,60,50,60,$red)
    GUISetOnEvent(-3, "_Exit")

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

    While 1
    _WinAPI_RedrawWindow($hWnd, 0, 0,$RDW_INTERNALPAINT)
    _GDIPlus_GraphicsClear($hBackbuffer)
    _GDIPlus_GraphicsDrawImage($hBackbuffer, $balloon_red, 50, 50)
    _gdiplus_graphicsdrawimagerect($hGraphic,$hBitmap,0,0,$iWidth,$iHeight)
    ; WM_PAINT wird nur aufgerufen, wenn alle Berechnungen fertig sind!
    ; In WM_PAINT wird selbst nichts berechnet, oder gezeichnet. diese Funktion wird nur das
    ; Bitmap-Objekt in das Grafik-Objekt übertragen.
    Sleep(1000)
    WEnd

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

    Func _Exit() ; Clean up resources
    _GDIPlus_GraphicsDispose($hGraphic) ; Grafikobjekt auflösen
    _GDIPlus_BitmapDispose($hBitmap); Bitmap auflösen
    _GDIPlus_ImageDispose($balloon_red); Bild auflösen
    _GDIPlus_ImageDispose($balloon_green); Bild auflösen
    _GDIPlus_ImageDispose($balloon_blue); Bild auflösen
    _GDIPlus_ImageDispose($balloon_yellow); Bild auflösen
    _GDIPlus_ImageDispose($balloon_pink); Bild auflösen
    _GDIPlus_ImageDispose($hBackground); Bild auflösen
    _GDIPlus_Shutdown() ; GDI+ Engine beenden
    Exit
    EndFunc ;==>_Exit

    [/autoit]

    Du hast öfter den Backbuffer gelöscht, bevor er auch nur auf das Fenster gemalt werden konnte.
    Ich habe es jetzt auch ohne die letzte Funktion gemacht

  • Jetzt habe ich einen schwarzen Hintergund und keinen Ballon (Ellipse)?

    Viele Grüße,
    HopFail

  • Wieso fällt eigentlich niemandem dieser peinliche Schreibfehler auf? 8|

    Schreibweise 1 ("balloon"):
    [Blockierte Grafik: http://img193.imageshack.us/img193/8703/schreibfehler2.png]

    Schreibweise 2 ("ballon"):
    [Blockierte Grafik: http://img714.imageshack.us/img714/9571/schreibfehler1.png]

    Also echt... :rolleyes:

  • hast du schonma probiert die antworten von name22 und m-obi zu kombinieren?
    dan gehts :D

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    Opt("GUIOnEventMode", 1)
    OnAutoItExitRegister("_Exit")

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

    _GDIPlus_Startup()

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

    Global $iWidth = 500, $iHeight = 600
    Global $iX = 0, $iY = 0
    $hGUI = GUICreate("TrapTheBalloon",$iWidth,$iHeight)
    $hWnd = WinGetHandle("TrapTheBalloon")
    GUISetState()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    ;Erstmal das normale Grafik-Objekt erstellen.
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
    ;Statt uns mit dem normalen Frontbuffer zufrieden zu geben, erstellen wir erstmal eine
    ;Bitmap, mit Bezug auf unser Grafikobjekt.
    $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    ;Nachdem unser Bitmap erstellt ist, holen wir uns den Graphics Context. Dieser
    ;wird von uns verwendet, um darin zu zeichnen
    $red = 0xFF000000 + 0xFF0000
    $green = 0xFF000000 + 0xFF0000
    $blue = 0xFF000000 + 0xFF0000
    $yellow = 0xFF000000 + 0xFF0000
    $pink = 0xFF000000 + 0xFF0000
    Global $hBackground = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\background.png")
    Global $balloon_red = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\balloon_red.png")
    Global $balloon_green = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\balloon_green.png")
    Global $balloon_blue = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\balloon_blue.png")
    Global $balloon_yellow = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\balloon_yellow.png")
    Global $balloon_pink = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\graphics\balloon_pink.png")
    _GDIPlus_GraphicsDrawEllipse($hBitmap,50,60,50,60,$red)
    GUISetOnEvent(-3, "_Exit")
    GUIRegisterMsg(0x000F, "WM_PAINT")

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

    While 1
    _GDIPlus_GraphicsClear($hBackbuffer)
    ; Superradierer benutzen um alten Backbuffer zu löschen
    _GDIPlus_GraphicsDrawRect($hBitmap,50,50,100,150)
    _WinAPI_RedrawWindow($hWnd, 0, 0,$RDW_INTERNALPAINT)
    ; WM_PAINT wird nur aufgerufen, wenn alle Berechnungen fertig sind!
    ; In WM_PAINT wird selbst nichts berechnet, oder gezeichnet. diese Funktion wird nur das
    ; Bitmap-Objekt in das Grafik-Objekt übertragen.
    Sleep(1000)
    WEnd

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

    Func _Exit() ; Clean up resources
    _GDIPlus_GraphicsDispose($hGraphic) ; Grafikobjekt auflösen
    _GDIPlus_BitmapDispose($hBitmap); Bitmap auflösen
    _GDIPlus_ImageDispose($balloon_red); Bild auflösen
    _GDIPlus_ImageDispose($balloon_green); Bild auflösen
    _GDIPlus_ImageDispose($balloon_blue); Bild auflösen
    _GDIPlus_ImageDispose($balloon_yellow); Bild auflösen
    _GDIPlus_ImageDispose($balloon_pink); Bild auflösen
    _GDIPlus_ImageDispose($hBackground); Bild auflösen
    _GDIPlus_Shutdown() ; GDI+ Engine beenden
    Exit
    EndFunc ;==>_Exit

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

    Func WM_PAINT()
    _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hBackground, 0, 0, $iWidth, $iHeight)
    _GDIPlus_GraphicsDrawImage($hBackbuffer, $balloon_red, 50, 50)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, $iX, $iY, $iWidth, $iHeight)
    ; _GDIPlus_GraphicsDrawImageRect() überträgt den Backbuffer in den Frontbuffer.
    ; Der erste Parameter ist unser Frontbuffer (Grafik Objekt).
    ; Der zweite ist unsere Bitmap, welche ja als BackBuffer fungiert.
    ; Darauf folgt der Abschnitt den man übertragen will.
    ; i.d.R. ist es 0, 0 für X und Y koordinaten, und die GUI Breite und Höhe für
    ; Width und Height. Kommt natürlich immer drauf an, wie groß euer Grafikobjekt ist,
    ; und ob ihr den vollen Teil zeichnen wollt.
    _GDIPlus_GraphicsFillRect($hBackbuffer, $iX, $iY, $iWidth, $iHeight)
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_PAINT

    [/autoit]