Hi @ all, ich hab mich in den letzten Tagen recht intensiv mit GDI+ beschäftigt und hatte auch dank Ubuntus Tut erste kleine Erfolge
Ich bastel gerade an einem Spiel im RPG-Style sprich Zelda,Pokemon was weiß ich
Naja ich dachte mir vielleicht interessierts manche Anfänger wie sie das mit dem Bildwechsel vor der Bewegung anstellen , ich poste jetzt
einfach das Grundgerüst von meinem Spiel (das momentane script ist schon sehr stark abgeändert), es ist einfach Ubuntu`s GDI+ Tut-Script nur etwas abgeändert , wiegesagt nichts besonderes aber es kann ja helfen/nicht schaden.
Die Bilder und das Script findet ihr im Anhang
Spoiler anzeigen
#include <GuiConstants.au3>
#include <GdiPlus.au3>;das include
#include <Misc.au3>
OnAutoItExitRegister("_end") ; die Funktion _end am Ende des Scriptes ausführen
_GDIPlus_Startup() ;Gdi starten
Global $x = 0;x und y deklarieren
Global $y = 0
Global $GUI_Width = 400
Global $GUI_Height = 380
Global $movespeed = 6
[/autoit] [autoit][/autoit] [autoit];----Bilder laden---------------------
Global $Figur_unten = _GDIPlus_ImageLoadFromFile(@ScriptDir &"/Bilder/figur_unten.gif")
Global $Figur_oben = _GDIPlus_ImageLoadFromFile(@ScriptDir &"/Bilder/figur_oben.gif")
Global $Figur_rechts = _GDIPlus_ImageLoadFromFile(@ScriptDir &"/Bilder/figur_rechts.gif")
Global $Figur_links = _GDIPlus_ImageLoadFromFile(@ScriptDir &"/Bilder/figur_links.gif")
Global $bk = _GDIPlus_ImageLoadFromFile(@ScriptDir & "/Bilder/bck.png")
$Gui = GUICreate("GDI+ Beispiel / Tutorial", $GUI_Width, $GUI_Height, 300,100)
$height = _GDIPlus_ImageGetHeight($Figur_unten)
$width = _GDIPlus_ImageGetWidth($Figur_unten)
$verhaelnis = $height / $width
$graphic = _GDIPlus_GraphicsCreateFromHWND($Gui);Frontbuffer
$bitmap = _GDIPlus_BitmapCreateFromGraphics($GUI_Width, $GUI_Height, $graphic)
$buffer = _GDIPlus_ImageGetGraphicsContext($bitmap);Backbuffer
Global $aktuelleFigur = $Figur_unten
GUISetState(@SW_SHOW)
While 1
[/autoit] [autoit][/autoit] [autoit]Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
Select
[/autoit] [autoit][/autoit] [autoit]Case _IsPressed(25) and not $x <= 0; ------------- geändert -------------
$x -= $movespeed
$aktuelleFigur=$Figur_links
Case _IsPressed(27) and $x <= $GUI_Width-41; ------------- geändert -------------
$x += $movespeed
$aktuelleFigur=$Figur_rechts
Case _IsPressed(26) and not $y <= 0; ------------- geändert -------------
$y -= $movespeed
$aktuelleFigur=$Figur_oben
Case _IsPressed(28) and $y <= $GUI_Height-80; ------------- geändert -------------
$y += $movespeed
$aktuelleFigur=$Figur_unten
EndSelect
_Draw()
[/autoit] [autoit][/autoit] [autoit]WEnd
[/autoit] [autoit][/autoit] [autoit]Func _end();die Exit funktion
_GDIPlus_GraphicsDispose($graphic);Grafik Objekt freigeben
_GDIPlus_GraphicsDispose($buffer)
_GDIPlus_BitmapDispose($bitmap)
;Bilder freigeben
_GDIPlus_ImageDispose($Figur_oben)
_GDIPlus_ImageDispose($Figur_unten)
_GDIPlus_ImageDispose($Figur_rechts)
_GDIPlus_ImageDispose($Figur_links)
_GDIPlus_ImageDispose($bk)
_GDIPlus_Shutdown();Ressourcen freigeben
EndFunc
Func _Draw()
_GDIPlus_GraphicsClear($buffer);Inhalt des Backbuffer`s wird gelöscht
_GDIPlus_GraphicsDrawImageRect($buffer,$bk,0,0,$GUI_Width, $GUI_Height)
_GDIPlus_GraphicsDrawImageRect($buffer,$aktuelleFigur,$x,$y,40,40 * $verhaelnis)
_GDIPlus_GraphicsDrawImage($graphic, $bitmap, 0, 0) ;Backbuffer wird an den Frontbuffer übergeben
;Sleep(30)
EndFunc