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
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
OnAutoItExitRegister("_Exit")
_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit]Global $iWidth = 500, $iHeight = 600
Global $iX = 0, $iY = 0
Global $aPos_Ellipse[4] = [-200, 100, 200, 200]
$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")
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
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
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
Hier der komplette Ordner als Archiv mit Grafiken.
autoit.de/wcf/attachment/9748/
Edit Oscar: Bitte keine Links zu Botforen setzen!