Hi ich würde gerne wissen wie ich ein GDI+ Objekt per Pfeiltasten bewegen kann??
Figur Mit Pfeiltasten steuern
-
- [ offen ]
-
crocojunk -
20. April 2010 um 14:58 -
Geschlossen -
Erledigt
-
-
- Offizieller Beitrag
Die Pfeiltasten kannst Du mit _IsPressed abfragen. Das GDI+ Objekt musst Du dann entsprechend der geänderten Position neuzeichnen.
-
vielleicht hilft dir auch das hier wieter(auch wenns komplexer ist):
-
Hier hab ich dir ein kleines Beispiel geschrieben, die Überprüfung ist in der While-Schleife:
Spoiler anzeigen
[autoit]
[/autoit] [autoit][/autoit] [autoit]
#include <GDIPlus.au3>
#include <GUIConstants.au3>
#include <Misc.au3>Global $GUIWidth = 500
[/autoit] [autoit][/autoit] [autoit]
Global $GUIHeight = 500
Global $iX = 100
Global $iY = 100
Global $RectWidth = 100
Global $RectHeight = 75_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]$hGUI = GUICreate("Beispiel", $GUIWidth, $GUIHeight)
[/autoit] [autoit][/autoit] [autoit]
GUISetState()$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
[/autoit] [autoit][/autoit] [autoit]
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($GUIWidth, $GUIHeight, $hGraphics)
$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
$BrushBlack = _GDIPlus_BrushCreateSolid(0xFF000000)_GDIPlus_GraphicsClear($hBuffer, 0xFFFFFFFF)
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_GraphicsFillRect($hBuffer, $iX, $iY, $RectWidth, $RectHeight, $BrushBlack)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $GUIWidth, $GUIHeight)While 1
[/autoit] [autoit][/autoit] [autoit]
$nMsg = GUIGetMsg(1)
Switch $nMsg[0]
Case $GUI_EVENT_CLOSE
_Exit()
EndSwitch
If _IsPressed("25") Then
$iX -= 3
_Draw()
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $GUIWidth, $GUIHeight)
EndIf
If _IsPressed("26") Then
$iY -= 3
_Draw()
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $GUIWidth, $GUIHeight)
EndIf
If _IsPressed("27") Then
$iX += 3
_Draw()
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $GUIWidth, $GUIHeight)
EndIf
If _IsPressed("28") Then
$iY += 3
_Draw()
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $GUIWidth, $GUIHeight)
EndIf
WEndFunc _Draw()
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_GraphicsClear($hBuffer, 0xFFFFFFFF)
_GDIPlus_GraphicsFillRect($hBuffer, $iX, $iY, $RectWidth, $RectHeight, $BrushBlack)
EndFunc ;==>_DrawFunc _Exit()
[/autoit]
_GDIPlus_BrushDispose($BrushBlack)
_GDIPlus_GraphicsDispose($hBuffer)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
Exit
EndFunc ;==>_Exit -
also ich hab das jetzt mal selber probiert aber bei mir kommen immer 3 errors.
hier ist der scriptSpoiler anzeigen
[autoit]#include <GDIPlus.au3>
[/autoit] [autoit][/autoit] [autoit]
#include <GUIConstants.au3>
#include <Misc.au3>Global $GuiWidth = 600
[/autoit] [autoit][/autoit] [autoit]
Global $GuiHeight = 600
Global $iX = 100
Global $iY = 100
Global $piewidth = 0
Global $pieheight = 320$form = GUICreate ("Test", 600,600)
[/autoit] [autoit][/autoit] [autoit]
$hwnd = WinGetHandle ($form)
GUISetBkColor (0x000000)
GUISetState (@SW_SHOW)_GDIPlus_Startup ()
[/autoit] [autoit][/autoit] [autoit]$hgraphics = _GDIPlus_GraphicsCreateFromHWND ($hwnd)
[/autoit] [autoit][/autoit] [autoit]
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($GUIWidth, $GUIHeight, $hGraphics)
$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
$pac = _GDIPlus_BrushCreateSolid (0xFFFFFF00)
_GDIPlus_GraphicsFillPie ($hgraphics, 50,50, 50, 50, 0, 320, $pac)While 1
[/autoit] [autoit][/autoit] [autoit]
$nMsg = GUIGetMsg(1)
Switch $nMsg[0]
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
If _IsPressed ("25") Then
$iX -= 3
Draw()
_GDIPlus_GraphicsFillPie ($hgraphics, 50,50,50,50,0,320, $pac)
EndIf
If _IsPressed ("26") Then
$iY -=3
Draw()
_GDIPlus_GraphicsFillPie ($hgraphics, 50,50,50,50,0,320,$pac)
EndIf
If _IsPressed ("27") Then
$iX +=3
Draw()
_GDIPlus_GraphicsFillPie ($hgraphics, 50,50,50,50,0,320,$pac)
EndIf
If _IsPressed ("28") Then
$iY +=3
Draw()
_GDIPlus_GraphicsFillPie ($hgraphics, 50,50,50,50,0,320,$pac)
EndIfFunc Draw()
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_GraphicsClear($hBuffer, 0xFFFFFFFF)
_GDIPlus_GraphicsFillPie ($hgraphics, 50,50,50,50,0,320,$pac)
EndFuncFunc _Exit()
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_BrushDispose($pac)
_GDIPlus_GraphicsDispose($hBuffer)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hgraphics)
_GDIPlus_Shutdown()
EndFuncWEnd
[/autoit]EDIT\\ Ich möchte nämlich pacman schreiben.
-
Und wo kommen die Errors?
Edit: Warum sind auch die beiden Funcs mit in der Schleife???
-
kommen bei euch keine??
ich kopier mal rein
C:\Users\User\Desktop\gd.au3(53,1) : ERROR: missing Wend.
Func
^
C:\Users\User\Desktop\gd.au3(26,1) : REF: missing Wend.
While
^
C:\Users\User\Desktop\gd.au3(66,1) : ERROR: syntax error
WEnd -
dann probiers man so:
Spoiler anzeigen
[autoit]#include <GDIPlus.au3>
[/autoit] [autoit][/autoit] [autoit]
#include <GUIConstants.au3>
#include <Misc.au3>Global $GuiWidth = 600
[/autoit] [autoit][/autoit] [autoit]
Global $GuiHeight = 600
Global $iX = 100
Global $iY = 100
Global $piewidth = 0
Global $pieheight = 320$form = GUICreate ("Test", 600,600)
[/autoit] [autoit][/autoit] [autoit]
$hwnd = WinGetHandle ($form)
GUISetBkColor (0x000000)
GUISetState (@SW_SHOW)_GDIPlus_Startup ()
[/autoit] [autoit][/autoit] [autoit]$hgraphics = _GDIPlus_GraphicsCreateFromHWND ($hwnd)
[/autoit] [autoit][/autoit] [autoit]
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($GUIWidth, $GUIHeight, $hGraphics)
$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
$pac = _GDIPlus_BrushCreateSolid (0xFFFFFF00)
_GDIPlus_GraphicsFillPie ($hgraphics, 50,50, 50, 50, 0, 320, $pac)While 1
[/autoit] [autoit][/autoit] [autoit]
$nMsg = GUIGetMsg(1)
Switch $nMsg[0]
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
If _IsPressed ("25") Then
$iX -= 3
Draw()
_GDIPlus_GraphicsFillPie ($hgraphics, 50,50,50,50,0,320, $pac)
EndIf
If _IsPressed ("26") Then
$iY -=3
Draw()
_GDIPlus_GraphicsFillPie ($hgraphics, 50,50,50,50,0,320,$pac)
EndIf
If _IsPressed ("27") Then
$iX +=3
Draw()
_GDIPlus_GraphicsFillPie ($hgraphics, 50,50,50,50,0,320,$pac)
EndIf
If _IsPressed ("28") Then
$iY +=3
Draw()
_GDIPlus_GraphicsFillPie ($hgraphics, 50,50,50,50,0,320,$pac)
EndIf
WEndFunc Draw()
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_GraphicsClear($hBuffer, 0xFFFFFFFF)
_GDIPlus_GraphicsFillPie ($hgraphics, 50,50,50,50,0,320,$pac)
EndFuncFunc _Exit()
[/autoit]
_GDIPlus_BrushDispose($pac)
_GDIPlus_GraphicsDispose($hBuffer)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hgraphics)
_GDIPlus_Shutdown()
EndFunc -
tu mal die funktionen Draw und exit aus der while schleife raus
EDIT: Zu langsam -.-
EDIT2: Nagut aber damit das ganze auch irgendwie funktioniert muss der code so aussehen:
Spoiler anzeigen
[autoit]#include <GDIPlus.au3>
[/autoit] [autoit][/autoit] [autoit]
#include <GUIConstants.au3>
#include <Misc.au3>Global $GuiWidth = 600
[/autoit] [autoit][/autoit] [autoit]
Global $GuiHeight = 600
Global $iX = 100
Global $iY = 100
Global $piewidth = 0
Global $pieheight = 320$form = GUICreate ("Test", 600,600)
[/autoit] [autoit][/autoit] [autoit]
$hwnd = WinGetHandle ($form)
GUISetBkColor (0x000000)
GUISetState (@SW_SHOW)_GDIPlus_Startup ()
[/autoit] [autoit][/autoit] [autoit]$hgraphics = _GDIPlus_GraphicsCreateFromHWND ($hwnd)
[/autoit] [autoit][/autoit] [autoit]
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($GUIWidth, $GUIHeight, $hGraphics)
$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
$pac = _GDIPlus_BrushCreateSolid (0xFFFFFF00)
_GDIPlus_GraphicsFillPie ($hgraphics, 100,100, 50, 50, 0, 320, $pac)While 1
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
$nMsg = GUIGetMsg(1)
Switch $nMsg[0]
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
If _IsPressed ("25") Then
$iX -= 3
Draw()
EndIf
If _IsPressed ("26") Then
$iY -=3
Draw()
EndIf
If _IsPressed ("27") Then
$iX +=3
Draw()
EndIf
If _IsPressed ("28") Then
$iY +=3
Draw()
EndIfWEnd
[/autoit] [autoit][/autoit] [autoit]Func Draw()
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_GraphicsClear($hgraphics)
_GDIPlus_GraphicsFillPie ($hgraphics, $iX,$iY,50,50,0,320,$pac)
EndFuncFunc _Exit()
[/autoit]
_GDIPlus_BrushDispose($pac)
_GDIPlus_GraphicsDispose($hBuffer)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hgraphics)
_GDIPlus_Shutdown()
EndFunc -
Du hast mein Skript falsch abgeschrieben.
Ich glaube nicht, dass Funcs in While Schleifen erstellt werden dürfen. -
Wenn man schon in den Backbuffer zeichnet, sollte man ihn auch auf den Frontbuffer bringen.
Spoiler anzeigen
[autoit]#include <GDIPlus.au3>
[/autoit] [autoit][/autoit] [autoit]
#include <GUIConstants.au3>
#include <Misc.au3>Global $GuiWidth = 600
[/autoit] [autoit][/autoit] [autoit]
Global $GuiHeight = 600
Global $iX = 100
Global $iY = 100
Global $piewidth = 0
Global $pieheight = 320$form = GUICreate ("Test", 600,600)
[/autoit] [autoit][/autoit] [autoit]
$hwnd = WinGetHandle ($form)
GUISetBkColor (0x000000)
GUISetState (@SW_SHOW)_GDIPlus_Startup ()
[/autoit] [autoit][/autoit] [autoit]$hGraphics = _GDIPlus_GraphicsCreateFromHWND ($hwnd)
[/autoit] [autoit][/autoit] [autoit]
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($GUIWidth, $GUIHeight, $hGraphics)
$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
$pac = _GDIPlus_BrushCreateSolid (0xFFFFFF00)
_GDIPlus_GraphicsFillPie ($hgraphics, 100,100, 50, 50, 0, 320, $pac)While 1
[/autoit] [autoit][/autoit] [autoit]
$nMsg = GUIGetMsg(1)
Switch $nMsg[0]
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
If _IsPressed ("25") Then
$iX -= 3
Draw()
EndIf
If _IsPressed ("26") Then
$iY -=3
Draw()
EndIf
If _IsPressed ("27") Then
$iX +=3
Draw()
EndIf
If _IsPressed ("28") Then
$iY +=3
Draw()
EndIf
WEndFunc Draw()
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_GraphicsClear($hBuffer)
_GDIPlus_GraphicsFillPie ($hBuffer, $iX,$iY,50,50,0,320,$pac)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $GUIWidth, $GuiHeight)
EndFuncFunc _Exit()
[/autoit]
_GDIPlus_BrushDispose($pac)
_GDIPlus_GraphicsDispose($hBuffer)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
EndFunc
@crocojunk Meinst du nicht, dass Pacman ein wenig zu hoch gegriffen ist? Fang doch erstmal mit was leichtem an. -
nun ja ich hatte irgendwie den einfall als ich auf youtube mir ein paar tuts angeguckt habe, ich wüsste auch nicht was ich sonst mit GDIplus machen sollte.
andere Frage um die figur zu verändern z.B. läuft nach unten wie kann ich das machen ?? Ich wollte dann erst den start und das Ende verändern aber irgendwie kam da was komisches raus und bevor ich da taage dran sitze um das rauszufinden dachte ich mir frag ich ein erfahrenen.
EDIT\\ Welche zahl steht für unten welche für die anderen???
-
So hab mich dann auch mal an dem PacMan versucht, mit der Vorlage von Croco.
Hier mein Script:Spoiler anzeigen
[autoit]#include <Array.au3>
[/autoit] [autoit][/autoit] [autoit]
#include <GDIPlus.au3>
#include <GUIConstants.au3>
#include <Misc.au3>Global $Timer
[/autoit] [autoit][/autoit] [autoit]
Global $GuiWidth = 600
Global $GuiHeight = 600
Global $iDirection = 3
Global $iX = 100
Global $iY = 100
Global $iAngleStart = 0
Global $iAngleEnd = 320
Global $piewidth = 0
Global $pieheight = 320Global $aBG[12][12] = [[1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0], _
[/autoit] [autoit][/autoit] [autoit]
[0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0], _
[0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0], _
[1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1], _
[1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1], _
[1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0], _
[1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1], _
[1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1], _
[0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1], _
[1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0], _
[1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0], _
[1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1]]$form = GUICreate ("Test", 600,600)
[/autoit] [autoit][/autoit] [autoit]
$hwnd = WinGetHandle ($form)
;GUISetBkColor (0x000000)
GUISetState (@SW_SHOW)_GDIPlus_Startup ()
[/autoit] [autoit][/autoit] [autoit]$hGraphics = _GDIPlus_GraphicsCreateFromHWND ($hwnd)
[/autoit] [autoit][/autoit] [autoit]
$hGraphics2 = _GDIPlus_GraphicsCreateFromHWND ($hwnd)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($GUIWidth, $GUIHeight, $hGraphics)
$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
$pac = _GDIPlus_BrushCreateSolid (0xFFFFFF00)
$Brush1 = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
$Brush2 = _GDIPlus_BrushCreateSolid(0xFF000000)
_BG()
_GDIPlus_GraphicsFillPie($hBuffer, $iX, $iY, 50, 50, $iAngleStart, $iAngleEnd, $pac)AdlibRegister("_AniPacMan", 400)
[/autoit] [autoit][/autoit] [autoit]While 1
[/autoit] [autoit][/autoit] [autoit]
If TimerDiff($Timer) > 200 Then Draw()$nMsg = GUIGetMsg()
[/autoit] [autoit][/autoit] [autoit]
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitchSelect
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
Case _IsPressed ("25") ;links
$iDirection = 1
$iAngleStart = 220
$iAngleEnd = 320
$iX -= 5
If TimerDiff($Timer) > 200 Then
Draw()
Else
Draw2()
EndIf
Case _IsPressed ("26") ;oben
$iDirection = 2
$iAngleStart = 270
$iAngleEnd = 320
$iY -= 5
If TimerDiff($Timer) > 200 Then
Draw()
Else
Draw2()
EndIf
Case _IsPressed ("27") ;rechts
$iDirection = 3
$iAngleStart = 0
$iAngleEnd = 320
$iX += 5
If TimerDiff($Timer) > 200 Then
Draw()
Else
Draw2()
EndIf
Case _IsPressed ("28") ;unten
$iDirection = 4
$iAngleStart = 130
$iAngleEnd = 320
$iY += 5
If TimerDiff($Timer) > 200 Then
Draw()
Else
Draw2()
EndIf
EndSelectWEnd
[/autoit] [autoit][/autoit] [autoit]Func Draw()
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_GraphicsClear($hBuffer)
_GDIPlus_GraphicsFillPie ($hBuffer, $iX,$iY,50,50,$iAngleStart,$iAngleEnd,$pac)
EndFuncFunc Draw2()
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_GraphicsClear($hBuffer)
Switch $iDirection
Case 1, 4
_GDIPlus_GraphicsFillPie ($hBuffer, $iX,$iY,50,50,$iAngleStart - 30,$iAngleEnd + 30,$pac)
Case 2, 3
_GDIPlus_GraphicsFillPie ($hBuffer, $iX,$iY,50,50,$iAngleStart,$iAngleEnd + 30,$pac)
EndSwitch
EndFuncFunc _Exit()
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_BrushDispose($pac)
_GDIPlus_GraphicsDispose($hBuffer)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_GraphicsDispose($hGraphics2)
_GDIPlus_Shutdown()
EndFuncFunc _AniPacMan()
[/autoit] [autoit][/autoit] [autoit]
Draw2()
$Timer = TimerInit()
EndFuncFunc _BG()
[/autoit]
For $y = 0 To UBound($aBG) - 1
For $x = 0 To UBound($aBG, 2) - 1
If $aBG[$y][$x] Then
_GDIPlus_GraphicsFillRect($hGraphics2, $x * 50, $y * 50, 50, 50, $Brush1)
Else
_GDIPlus_GraphicsFillRect($hGraphics2, $x * 50, $y * 50, 50, 50, $Brush2)
EndIf
Next
Next
EndFuncNun ist es aber so, dass man den PacMan nicht sieht, woran liegt das?
-
ich hab nur 1 frage wie kann ich machen das mein pacman auf der anderen seite wieder rauskommt??
-
@m-obi ich weiß nicht genau wo der fehler liegt ich glaube der pacman wird übermalt.
wiegesagt ich mach GDIPlus zum erszen mal.
EDIT\\ Welcher befehehl macht das die figur auf der anderen seite wieder rauskommt??
-
Achja, zu der _IsPressed() Funktion, mit der kannst du auch viele andere Tasten prüfen (Die Hilfe hilft dem Hilfesuchenden!)
-
das mit ispressed hab ich jetzt schon nur halt brauch ich noch das er bei einem fenster rauskommt und beim anderen reinkommt
-
Du meinst wenn jetzt der PacMan sagen wir nach rechts geht, unten am Rand verschwindet, soll er links wieder auftauchen? Das kenn ich von dem richtigen PacMan garnicht. Der geht doch durchs Labyrinth.
-
also du musst die koordinaten abfragen.... und dann bestimmte koordinaten raussuchen und wenn $iX /$iY größer als XXX Then $$iX /$iY = XYX
-
Wenn z.b. die Koordinaten die Breite des Fensters überschreiten, musst du die positionen einfach wieder auf 0 oder weniger setzen.
-