gottygolly Posted June 3, 2015 Share Posted June 3, 2015 I'm currently working on a project and I've ran into a problem and I was hoping one of the wizards could solve this (or someone that's smarter than me, shouldn't be hard to find).#include<gdiplus.au3> $gui = GUICreate("",640,480,-1,-1) Opt("GUIOnEventMode",1) GUISetOnEvent(-3,"_Exit") GUISetState() _GDIPlus_Startup() $hwnd = _GDIPlus_GraphicsCreateFromHWND($gui) $bitmap = _GDIPlus_BitmapCreateFromGraphics(640,480,$hwnd) $buffer = _GDIPlus_ImageGetGraphicsContext($bitmap) $pen = _GDIPlus_PenCreate(0xFFFF0000,10) $pen2 = _GDIPlus_PenCreate(0xFFFFFFFF,10) While 1 _GDIPlus_GraphicsClear($buffer) _GDIPlus_GraphicsDrawLine($buffer,10,10,10,100,$pen) ;When this one moves it will cause the the other buffer to move. Simulating a larger area moved. _GDIPlus_GraphicsDrawLine($buffer,100,10,100,100,$pen2) ;Instead of "$buffer" instead have it set to say "$buffer_background". _GDIPlus_GraphicsDrawImageRect($hwnd,$bitmap,0,0,640,480) Sleep(10) WEnd Func _Exit() _GDIPlus_PenDispose($pen2) _GDIPlus_PenDispose($pen) _GDIPlus_GraphicsDispose($buffer) _GDIPlus_BitmapDispose($bitmap) _GDIPlus_GraphicsDispose($hwnd) _GDIPlus_Shutdown() Exit EndFuncMy problem is I need to have lets say a triple buffer for the lack of a better term. I want to be able to move the red line and when the red line hits one of the walls of the GUI it then stops moving and it then moves the white lines buffer. Kind of like a giant map.I don't know if I explained myself very well so please ask questions if it will help you because if it helps you it'll help me too.Thanks in advance (in case I fall asleep) Link to comment Share on other sites More sharing options...
UEZ Posted June 3, 2015 Share Posted June 3, 2015 Can you describe a little more in detail what you are planning to do? I don't understand the meaning of the triple buffer here. Thanks. Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
gottygolly Posted June 3, 2015 Author Share Posted June 3, 2015 I tried to use some example code but I guess it wasn't enough.expandcollapse popup#include<array.au3> #include<gdiplus.au3> #include<misc.au3> #include<windowsconstants.au3> $gui = GUICreate("",640,480,-1,-1,$WS_MAXIMIZEBOX) Opt("GUIOnEventMode",1) GUISetOnEvent(-3,"_Exit") $got = False $spawned = False $speed = 25 ;Adjust to move faster/slower. Note: the number is the number of pixels moved. $car_look_forward = True $car_look_left = False $car_look_right = False $car_look_back = False Local $wheel[4] $x_top_body = 285 $y_top_body = 350 $x_top_old = 285 $y_top_old = 350 $x_bottom_body = 285 $y_bottom_body = 425 $x_top_wheel = $x_top_body - 25 $y_top_wheel = $y_top_body $x_bottom_wheel = $x_top_body - 25 $y_bottom_wheel = $y_top_body + 20 $x_top_window = $x_top_body + 1 $y_top_window = $y_top_body + 5 $x_bottom_window = $x_top_body + 1 $y_bottom_window = $y_top_body + 25 $x_wheel_turn = 50 $y_wheel_turn = 55 $pressed = False Local $fps GUISetState() $y_rect = 0 $x_rect = 0 $gui_cp_og = WinGetPos($gui) $size_x = $gui_cp_og[2] $size_y = $gui_cp_og[3] AdlibRegister("FPS", 1000) _GDIPlus_Startup() $hwnd = _GDIPlus_GraphicsCreateFromHWND($gui) $bitmap = _GDIPlus_BitmapCreateFromGraphics(2000, 1000, $hwnd) $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap) $bitmap_2 = _GDIPlus_BitmapCreateFromGraphics(2000, 1000, $hwnd) $backbuffer_2 = _GDIPlus_ImageGetGraphicsContext($bitmap_2) $pen_body = _GDIPlus_PenCreate(0xFF000FF00,30) $pen_window = _GDIPlus_PenCreate(0xFFFFFFFFF,20) $pen_wheels = _gdiplus_pencreate(0x093456634,10) $pen_barrel = _GDIPlus_PenCreate(0x0F3456634,10) $pen_headlight = _GDIPlus_PenCreate(0xFFFFFFFFF,5) $brush_light = _GDIPlus_BrushCreateSolid(0xF0FFFFF00) Local $apoints[4][2],$apoints2[4][2] While 1 $gui_cp = WinGetPos($gui) $fps += 1 _GDIPlus_GraphicsClear($backbuffer) $path = _GDIPlus_PathCreate() If $y_top_body <> $y_top_old Or $x_top_body <> $x_top_old Then $x_top_old = $x_top_body $y_top_old = $y_top_body _Spawn_barrel() EndIf If $gui_cp[2] <> $gui_cp_og[2] Or $gui_cp[3] <> $gui_cp_og[3] Then $hwnd = _GDIPlus_GraphicsCreateFromHWND($gui) $bitmap = _GDIPlus_BitmapCreateFromGraphics(2000, 1000, $hwnd) $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap) $bitmap_2 = _GDIPlus_BitmapCreateFromGraphics(2000, 1000, $hwnd) $backbuffer_2 = _GDIPlus_ImageGetGraphicsContext($bitmap_2) $gui_cp_og[2] = $gui_cp[2] $gui_cp_og[3] = $gui_cp[3] EndIf ;_GDIPlus_GraphicsClear($backbuffer_2) ;Double buffer. If _IsPressed("26") And Not _IsPressed("25") And Not _IsPressed("27") Then ;Up If $car_look_forward = True Then If $y_top_body >= 75 Then $y_top_body -= $speed $y_bottom_body -= $speed $y_top_window -= $speed $y_bottom_window -= $speed $y_top_wheel -= $speed $y_bottom_wheel -= $speed Else $y_rect += $speed EndIf ElseIf $car_look_left = True Then If $x_top_body >= 75 Then $x_top_body -= $speed $x_bottom_body -= $speed $x_top_window -= $speed $x_bottom_window -= $speed $x_top_wheel -= $speed $x_bottom_wheel -= $speed Else $x_rect += $speed EndIf ElseIf $car_look_back = True Then If $y_top_body <= $gui_cp[3]-75 Then $y_top_body += $speed $y_bottom_body += $speed $y_top_window += $speed $y_bottom_window += $speed $y_top_wheel += $speed $y_bottom_wheel += $speed Else $y_rect -= $speed EndIf ElseIf $car_look_right = True Then If $x_top_body <= $gui_cp[2]-75 Then $x_top_body += $speed $x_bottom_body += $speed $x_top_window += $speed $x_bottom_window += $speed $x_top_wheel += $speed $x_bottom_wheel += $speed Else $x_rect -= $speed EndIf EndIf EndIf If _IsPressed("28") And Not _IsPressed("25") And Not _IsPressed("27") Then ;Down If $car_look_forward = True Then $y_top_body += $speed $y_bottom_body += $speed $y_top_window += $speed $y_bottom_window += $speed $y_top_wheel += $speed $y_bottom_wheel += $speed $y_rect -= $speed ElseIf $car_look_left = True Then $x_top_body += $speed $x_bottom_body += $speed $x_top_window += $speed $x_bottom_window += $speed $x_top_wheel += $speed $x_bottom_wheel += $speed $x_rect -= $speed ElseIf $car_look_back = True Then $y_top_body -= $speed $y_bottom_body -= $speed $y_top_window -= $speed $y_bottom_window -= $speed $y_top_wheel -= $speed $y_bottom_wheel -= $speed $y_rect += $speed ElseIf $car_look_right = True Then $x_top_body -= $speed $x_bottom_body -= $speed $x_top_window -= $speed $x_bottom_window -= $speed $x_top_wheel -= $speed $x_bottom_wheel -= $speed $x_rect += $speed EndIf EndIf If _IsPressed("25") Then ;Left Sleep(100) _Change_Direction() ElseIf _IsPressed("27") Then ;Right Sleep(100) _Change_Direction_Right() EndIf _Curve() _GDIPlus_GraphicsFillClosedCurve($backbuffer, $aPoints,$brush_light) _GDIPlus_GraphicsFillClosedCurve($backbuffer, $aPoints2,$brush_light) _GDIPlus_GraphicsDrawLine($backbuffer,$x_top_body,$y_top_body,$x_bottom_body,$y_bottom_body,$pen_body) _GDIPlus_GraphicsDrawLine($backbuffer,$x_top_window,$y_top_window,$x_bottom_window,$y_bottom_window,$pen_window) _GDIPlus_GraphicsDrawLine($backbuffer,$x_top_wheel,$y_top_wheel,$x_bottom_wheel,$y_bottom_wheel,$pen_wheels);front_left _GDIPlus_GraphicsDrawLine($backbuffer,$x_top_wheel+$x_wheel_turn,$y_top_wheel,$x_bottom_wheel+$x_wheel_turn,$y_bottom_wheel,$pen_wheels);front_right _GDIPlus_GraphicsDrawLine($backbuffer,$x_top_wheel,$y_top_wheel+$y_wheel_turn,$x_bottom_wheel,$y_bottom_wheel+$y_wheel_turn,$pen_wheels);back_left _GDIPlus_GraphicsDrawLine($backbuffer,$x_top_wheel+$x_wheel_turn,$y_top_wheel+$y_wheel_turn,$x_bottom_wheel+$x_wheel_turn,$y_bottom_wheel+$y_wheel_turn,$pen_wheels);back_right If $spawned = True Then _GDIPlus_GraphicsDrawLine($backbuffer_2,$ran_x_line,$ran_y_line,$ran_x_line,$ran_y_line_solid,$pen_barrel) EndIf Sleep(100) _GDIPlus_GraphicsDrawImageRect($hwnd, $bitmap, 0, 0, 2000, 1000) ;_GDIPlus_GraphicsDrawLine($backbuffer_2,0,0,100,100,$pen_body) _GDIPlus_GraphicsDrawImageRect($hwnd, $bitmap_2, $x_rect, $y_rect, 2000, 1000) WEnd Func _Exit() ;Exit? _GDIPlus_BrushDispose($brush_light) _GDIPlus_PenDispose($pen_body) _GDIPlus_PenDispose($pen_window) _GDIPlus_PenDispose($pen_wheels) _GDIPlus_PenDispose($pen_barrel) _GDIPlus_PenDispose($pen_headlight) _GDIPlus_GraphicsDispose($backbuffer) _GDIPlus_GraphicsDispose($backbuffer_2) _GDIPlus_BitmapDispose($bitmap) _GDIPlus_BitmapDispose($bitmap_2) _GDIPlus_PathDispose($path) _GDIPlus_GraphicsDispose($hwnd) _GDIPlus_Shutdown() Exit EndFunc Func _Change_Direction() ;Changes directions when you press the left arrow key. If $car_look_left = False And $car_look_forward = True Then $x_top = $x_top_body $x_bottom = $x_bottom_body $y_top = $y_top_body $y_bottom = $y_bottom_body $x_wheel_top = $x_top_wheel $y_wheel_top = $y_top_wheel $x_wheel_bottom = $x_bottom_wheel $y_wheel_bottom = $y_bottom_wheel $x_window_top = $x_top_window $y_window_top = $y_top_window $x_window_bottom = $x_bottom_window $y_window_bottom = $y_bottom_window $x_top_body = $x_top+(($y_top-$y_bottom)/2) $y_top_body = $y_top-(($y_top-$y_bottom)/2) $x_bottom_body = $x_bottom-(($y_top-$y_bottom)/2) $y_bottom_body = $y_bottom+(($y_top-$y_bottom)/2) $x_top_wheel = $x_wheel_top-(($y_wheel_top-$y_wheel_bottom)/2) $y_top_wheel = $y_wheel_top-(($y_wheel_top-$y_wheel_bottom)/2) $x_bottom_wheel = $x_wheel_bottom+(($y_wheel_top-$y_wheel_bottom)/2) $y_bottom_wheel = $y_wheel_bottom+(($y_wheel_top-$y_wheel_bottom)/2) $x_top_window = $x_top_body + 5 $y_top_window = $y_top_body + 1 $x_bottom_window = $x_top_body + 25 $y_bottom_window = $y_top_body + 1 $car_look_forward = False $car_look_left = True $car_look_right = False $car_look_back = False ElseIf $car_look_left = True And $car_look_back = False Then $x_top = $x_top_body $x_bottom = $x_bottom_body $y_top = $y_top_body $y_bottom = $y_bottom_body $x_wheel_top = $x_top_wheel $y_wheel_top = $y_top_wheel $x_wheel_bottom = $x_bottom_wheel $y_wheel_bottom = $y_bottom_wheel $x_window_top = $x_top_window $y_window_top = $y_top_window $x_window_bottom = $x_bottom_window $y_window_bottom = $y_bottom_window $x_top_body = $x_top-(($x_top-$x_bottom)/2) $y_top_body = $y_top-(($x_top-$x_bottom)/2) $x_bottom_body = $x_bottom+(($x_top-$x_bottom)/2) $y_bottom_body = $y_bottom+(($x_top-$x_bottom)/2) $x_top_wheel = $x_wheel_top-(($x_wheel_top-$x_wheel_bottom)/2) $y_top_wheel = $y_wheel_top-(($x_wheel_top-$x_wheel_bottom)/2) $x_bottom_wheel = $x_wheel_bottom+(($x_wheel_top-$x_wheel_bottom)/2) $y_bottom_wheel = $y_wheel_bottom+(($x_wheel_top-$x_wheel_bottom)/2) $x_top_window = $x_top_body + 1 $y_top_window = $y_top_body - 5 $x_bottom_window = $x_top_body + 1 $y_bottom_window = $y_top_body - 25 $car_look_forward = False $car_look_left = False $car_look_right = False $car_look_back = True ElseIf $car_look_back = True And $car_look_right = False Then $x_top = $x_top_body $x_bottom = $x_bottom_body $y_top = $y_top_body $y_bottom = $y_bottom_body $x_wheel_top = $x_top_wheel $y_wheel_top = $y_top_wheel $x_wheel_bottom = $x_bottom_wheel $y_wheel_bottom = $y_bottom_wheel $x_window_top = $x_top_window $y_window_top = $y_top_window $x_window_bottom = $x_bottom_window $y_window_bottom = $y_bottom_window $x_top_body = $x_top+(($y_top-$y_bottom)/2) $y_top_body = $y_top-(($y_top-$y_bottom)/2) $x_bottom_body = $x_bottom-(($y_top-$y_bottom)/2) $y_bottom_body = $y_bottom+(($y_top-$y_bottom)/2) $x_top_wheel = $x_wheel_top-(($y_wheel_top-$y_wheel_bottom)/2) $y_top_wheel = $y_wheel_top-(($y_wheel_top-$y_wheel_bottom)/2) $x_bottom_wheel = $x_wheel_bottom+(($y_wheel_top-$y_wheel_bottom)/2) $y_bottom_wheel = $y_wheel_bottom+(($y_wheel_top-$y_wheel_bottom)/2) $x_top_window = $x_top_body - 5 $y_top_window = $y_top_body + 1 $x_bottom_window = $x_top_body - 25 $y_bottom_window = $y_top_body + 1 $car_look_forward = False $car_look_left = False $car_look_right = True $car_look_back = False ElseIf $car_look_right = True And $car_look_forward = False Then $x_top = $x_top_body $x_bottom = $x_bottom_body $y_top = $y_top_body $y_bottom = $y_bottom_body $x_wheel_top = $x_top_wheel $y_wheel_top = $y_top_wheel $x_wheel_bottom = $x_bottom_wheel $y_wheel_bottom = $y_bottom_wheel $x_window_top = $x_top_window $y_window_top = $y_top_window $x_window_bottom = $x_bottom_window $y_window_bottom = $y_bottom_window $x_top_body = $x_top-(($x_top-$x_bottom)/2) $y_top_body = $y_top-(($x_top-$x_bottom)/2) $x_bottom_body = $x_bottom+(($x_top-$x_bottom)/2) $y_bottom_body = $y_bottom+(($x_top-$x_bottom)/2) $x_top_wheel = $x_wheel_top-(($x_wheel_top-$x_wheel_bottom)/2) $y_top_wheel = $y_wheel_top-(($x_wheel_top-$x_wheel_bottom)/2) $x_bottom_wheel = $x_wheel_bottom+(($x_wheel_top-$x_wheel_bottom)/2) $y_bottom_wheel = $y_wheel_bottom+(($x_wheel_top-$x_wheel_bottom)/2) $x_top_window = $x_top_body + 1 $y_top_window = $y_top_body + 5 $x_bottom_window = $x_top_body + 1 $y_bottom_window = $y_top_body + 25 $car_look_forward = True $car_look_left = False $car_look_right = False $car_look_back = False EndIf EndFunc Func _Change_Direction_Right() ;Changes direction when you press the right arrow key. If $car_look_right = False And $car_look_forward = True Then $x_top = $x_top_body $x_bottom = $x_bottom_body $y_top = $y_top_body $y_bottom = $y_bottom_body $x_wheel_top = $x_top_wheel $y_wheel_top = $y_top_wheel $x_wheel_bottom = $x_bottom_wheel $y_wheel_bottom = $y_bottom_wheel $x_window_top = $x_top_window $y_window_top = $y_top_window $x_window_bottom = $x_bottom_window $y_window_bottom = $y_bottom_window $x_top_body = $x_top-(($y_top-$y_bottom)/2) $y_top_body = $y_top-(($y_top-$y_bottom)/2) $x_bottom_body = $x_bottom+(($y_top-$y_bottom)/2) $y_bottom_body = $y_bottom+(($y_top-$y_bottom)/2) $x_top_wheel = $x_wheel_top-(($y_wheel_top-$y_wheel_bottom)/2) $y_top_wheel = $y_wheel_top-(($y_wheel_top-$y_wheel_bottom)/2) $x_bottom_wheel = $x_wheel_bottom+(($y_wheel_top-$y_wheel_bottom)/2) $y_bottom_wheel = $y_wheel_bottom+(($y_wheel_top-$y_wheel_bottom)/2) $x_top_window = $x_top_body - 5 $y_top_window = $y_top_body + 1 $x_bottom_window = $x_top_body - 25 $y_bottom_window = $y_top_body + 1 $car_look_forward = False $car_look_left = False $car_look_right = True $car_look_back = False ElseIf $car_look_right = True And $car_look_back = False Then $x_top = $x_top_body $x_bottom = $x_bottom_body $y_top = $y_top_body $y_bottom = $y_bottom_body $x_wheel_top = $x_top_wheel $y_wheel_top = $y_top_wheel $x_wheel_bottom = $x_bottom_wheel $y_wheel_bottom = $y_bottom_wheel $x_window_top = $x_top_window $y_window_top = $y_top_window $x_window_bottom = $x_bottom_window $y_window_bottom = $y_bottom_window $x_top_body = $x_top-(($x_top-$x_bottom)/2) $y_top_body = $y_top+(($x_top-$x_bottom)/2) $x_bottom_body = $x_bottom+(($x_top-$x_bottom)/2) $y_bottom_body = $y_bottom-(($x_top-$x_bottom)/2) $x_top_wheel = $x_wheel_top-(($x_wheel_top-$x_wheel_bottom)/2) $y_top_wheel = $y_wheel_top-(($x_wheel_top-$x_wheel_bottom)/2) $x_bottom_wheel = $x_wheel_bottom+(($x_wheel_top-$x_wheel_bottom)/2) $y_bottom_wheel = $y_wheel_bottom+(($x_wheel_top-$x_wheel_bottom)/2) $x_top_window = $x_top_body + 1 $y_top_window = $y_top_body - 5 $x_bottom_window = $x_top_body + 1 $y_bottom_window = $y_top_body - 25 $car_look_forward = False $car_look_left = False $car_look_right = False $car_look_back = True ElseIf $car_look_back = True And $car_look_left = False Then $x_top = $x_top_body $x_bottom = $x_bottom_body $y_top = $y_top_body $y_bottom = $y_bottom_body $x_wheel_top = $x_top_wheel $y_wheel_top = $y_top_wheel $x_wheel_bottom = $x_bottom_wheel $y_wheel_bottom = $y_bottom_wheel $x_window_top = $x_top_window $y_window_top = $y_top_window $x_window_bottom = $x_bottom_window $y_window_bottom = $y_bottom_window $x_top_body = $x_top-(($y_top-$y_bottom)/2) $y_top_body = $y_top-(($y_top-$y_bottom)/2) $x_bottom_body = $x_bottom+(($y_top-$y_bottom)/2) $y_bottom_body = $y_bottom+(($y_top-$y_bottom)/2) $x_top_wheel = $x_wheel_top-(($y_wheel_top-$y_wheel_bottom)/2) $y_top_wheel = $y_wheel_top-(($y_wheel_top-$y_wheel_bottom)/2) $x_bottom_wheel = $x_wheel_bottom+(($y_wheel_top-$y_wheel_bottom)/2) $y_bottom_wheel = $y_wheel_bottom+(($y_wheel_top-$y_wheel_bottom)/2) $x_top_window = $x_top_body + 5 $y_top_window = $y_top_body - 1 $x_bottom_window = $x_top_body + 25 $y_bottom_window = $y_top_body - 1 $car_look_forward = False $car_look_left = True $car_look_right = False $car_look_back = False ElseIf $car_look_left = True And $car_look_forward = False Then $x_top = $x_top_body $x_bottom = $x_bottom_body $y_top = $y_top_body $y_bottom = $y_bottom_body $x_wheel_top = $x_top_wheel $y_wheel_top = $y_top_wheel $x_wheel_bottom = $x_bottom_wheel $y_wheel_bottom = $y_bottom_wheel $x_window_top = $x_top_window $y_window_top = $y_top_window $x_window_bottom = $x_bottom_window $y_window_bottom = $y_bottom_window $x_top_body = $x_top-(($x_top-$x_bottom)/2) $y_top_body = $y_top+(($x_top-$x_bottom)/2) $x_bottom_body = $x_bottom+(($x_top-$x_bottom)/2) $y_bottom_body = $y_bottom-(($x_top-$x_bottom)/2) $x_top_wheel = $x_wheel_top-(($x_wheel_top-$x_wheel_bottom)/2) $y_top_wheel = $y_wheel_top-(($x_wheel_top-$x_wheel_bottom)/2) $x_bottom_wheel = $x_wheel_bottom+(($x_wheel_top-$x_wheel_bottom)/2) $y_bottom_wheel = $y_wheel_bottom+(($x_wheel_top-$x_wheel_bottom)/2) $x_top_window = $x_top_body + 1 $y_top_window = $y_top_body + 5 $x_bottom_window = $x_top_body + 1 $y_bottom_window = $y_top_body + 25 $car_look_forward = True $car_look_left = False $car_look_right = False $car_look_back = False EndIf EndFunc Func _Curve() ;This is the headlight size function. If $car_look_forward = True Then $aPoints[0][0] = 3 $aPoints[1][0] = $x_top_body-20 $aPoints[1][1] = $y_top_body-10 $aPoints[2][0] = $x_top_body-80 $aPoints[2][1] = $y_top_body-90 $aPoints[3][0] = $x_top_body+40 $aPoints[3][1] = $y_top_body-90 $aPoints2[0][0] = 3 $aPoints2[1][0] = $x_top_body+20 $aPoints2[1][1] = $y_top_body-10 $aPoints2[2][0] = $x_top_body-40 $aPoints2[2][1] = $y_top_body-90 $aPoints2[3][0] = $x_top_body+80 $aPoints2[3][1] = $y_top_body-90 ElseIf $car_look_left = True Then $aPoints[0][0] = 3 $aPoints[1][0] = $x_top_body-10 $aPoints[1][1] = $y_top_body-20 $aPoints[2][0] = $x_top_body-90 $aPoints[2][1] = $y_top_body-80 $aPoints[3][0] = $x_top_body-90 $aPoints[3][1] = $y_top_body+40 $aPoints2[0][0] = 3 $aPoints2[1][0] = $x_top_body-10 $aPoints2[1][1] = $y_top_body+20 $aPoints2[2][0] = $x_top_body-90 $aPoints2[2][1] = $y_top_body-40 $aPoints2[3][0] = $x_top_body-90 $aPoints2[3][1] = $y_top_body+80 ElseIf $car_look_back = True Then $aPoints[0][0] = 3 $aPoints[1][0] = $x_top_body+20 $aPoints[1][1] = $y_top_body+10 $aPoints[2][0] = $x_top_body+80 $aPoints[2][1] = $y_top_body+90 $aPoints[3][0] = $x_top_body-40 $aPoints[3][1] = $y_top_body+90 $aPoints2[0][0] = 3 $aPoints2[1][0] = $x_top_body-20 $aPoints2[1][1] = $y_top_body+10 $aPoints2[2][0] = $x_top_body+40 $aPoints2[2][1] = $y_top_body+90 $aPoints2[3][0] = $x_top_body-80 $aPoints2[3][1] = $y_top_body+90 ElseIf $car_look_right = True Then $aPoints[0][0] = 3 $aPoints[1][0] = $x_top_body+10 $aPoints[1][1] = $y_top_body+20 $aPoints[2][0] = $x_top_body+90 $aPoints[2][1] = $y_top_body+80 $aPoints[3][0] = $x_top_body+90 $aPoints[3][1] = $y_top_body-40 $aPoints2[0][0] = 3 $aPoints2[1][0] = $x_top_body+10 $aPoints2[1][1] = $y_top_body-20 $aPoints2[2][0] = $x_top_body+90 $aPoints2[2][1] = $y_top_body+40 $aPoints2[3][0] = $x_top_body+90 $aPoints2[3][1] = $y_top_body-80 EndIf EndFunc Func FPS() ;Used this from the Suspended Cloth Simulation. WinSetTitle($GUI,"","FPS: " & $fps) $fps = 0x00000000 EndFunc Func _Spawn_barrel() If $got = False And $spawned = False Then Global $ran_x_line = Random(5,470) Global $ran_y_line = Random(5,470) Global $ran_y_line_solid = $ran_y_line + 20 _GDIPlus_GraphicsDrawLine($backbuffer_2,$ran_x_line,$ran_y_line,$ran_x_line,$ran_y_line_solid,$pen_barrel) $got = True $spawned = True EndIf EndFuncThe code above is my actual script. If you move you can see that a "barrel" spawns but flickers. Is there a way to paint the barrel so it won't flicker but still moves the way it moves right now? Link to comment Share on other sites More sharing options...
binhnx Posted June 3, 2015 Share Posted June 3, 2015 (edited) You've misunderstand the term "multiple buffering". The flickering is cause by a sequence of slow-painting-action *directly* to the screen buffer.To solve the flickering issues, you actually need some kind of multiple buffering, in this case double buffering is enough. To be double buffered, the entire frame need to be paint to *one* buffer (back-buffer), that buffer will be flip/copy to the screen buffer (front-buffer) to show directly in the screen (eg. monitor), which you've done by using _GDIPlus_GraphicsDrawImageRectThat function should be called *only one* each time you finish with the back-buffer, because its the one which directly communicate with the front buffer.It seems that due to misunderstanding, you're using *2* buffers and then call copy function *twice*. With your 2000x1000 = 2Megapixel large buffer, with the low speed of GDI+ (all done by CPU, not by GPU acceleration), with two sequence call to it, all the condition are met to make your game flicker like crazy.So you need to use only one buffer. Calculate all the coordinates and paint the right thing to the right location in the back buffer, then copy it to the front buffer. Don't use 2 back buffers and copy twice. (Indeed, in triple-buffering, you also copy once and only once. There are 2 back buffers, but there is always (at a specified moment) only one back buffer to be painted to, and one to be swapped/copy to the front buffer. When the painting finished, we flip 2 back buffers)And a footnote: using loopy-based input model is quite rarely used in game development. Think like this, you and your friend need to meet to exchange some information. The correct way is, when you arrive at her house, you need to press doorbell (or phone her) so she know you've arrived. But a lot scripter did another way, they ask their girl-friends to go out and check for your arrival, say, every 100 milliseconds ('kay, in real world, it can be 15 mins or 2 hours interval) but its totally inefficient and unreliable. You can see that. If you busy all the day and can only come to her house at the very end of the day, so she need to go out and check several times to solve nothing. The more frequently she go out and looking for you, the more inefficient. Yes, you can ask her go out less frequently, but there are also a cavet: you can arrive at the time she is inside her house. Since 2 you have none method to communicate with each other, she don't know that you've arrived. And you, when don't see her outside, you also go back to your home without any information/gifts. Say the computer words, when your user press their keyboard button but your apps is currently executing this lineSleep(100)so the user's press event will silently killed. You can only *reduce* (not remove) the case the event loss by increase the frequency, but it effect the performance (more inefficient). Switch your app to event mode. Create some 'dummy' control in your GUI, and take a look at the GUISetAccelerators function. This way every event is catch when it comes, efficiently and reliability. Edited June 3, 2015 by binhnx 99 little bugs in the code 99 little bugs! Take one down, patch it around 117 little bugs in the code! Link to comment Share on other sites More sharing options...
gottygolly Posted June 3, 2015 Author Share Posted June 3, 2015 Thanks for all the help binhnx, you brought up some points that I never even thought of and helped a lot with what I am working on. Can't thank you enough. Link to comment Share on other sites More sharing options...
UEZ Posted June 3, 2015 Share Posted June 3, 2015 (edited) Well, I didn't realize the huge "back buffer" you have created but that shouldn't be a big problem if you copy only the portion of that huge back buffer that fits to your GUI using _GDIPlus_GraphicsDrawImageRectRect. The only way to speed it up is to mix-up GDI and GDI+ by using _WinAPI_BitBlt.An example can be found here: CoSiNUs brOTHerS inTRO Short explanation to $hwnd = _GDIPlus_GraphicsCreateFromHWND($gui) $bitmap = _GDIPlus_BitmapCreateFromGraphics(2000, 1000, $hwnd) $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)What you are here doing is to create the graphic handle which will be shown in the GUI. You can either draw directly to this graphic handle ($hwnd) or draw to the $backbuffer handle which points to the bitmap (wrapper) because you cannot draw directly to bitmaps (except the pixel set function). Only drawn to $hwnd handle will be shown directly in the GUI. Only after _GDIPlus_GraphicsDrawImageRect you will see the content of the bitmap in the GUI.These processes are running sequentially not in parallel!To animate something without flickering you have to finish drawing on the back buffer and then copy the result (bitmap) to the GUI.Using more than one back buffer make only sense if you need additional operations like rotation whereas the visible graphic handle shouldn't be impacted by the rotation. That means the back buffers will be copied sequentially to the GUI (overlapped). Edited June 4, 2015 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
gottygolly Posted June 3, 2015 Author Share Posted June 3, 2015 Thanks for all the help guys, I've learned a lot in just the past few hours but some things I don't quite get.so the user's press event will silently killed. You can only *reduce* (not remove) the case the event loss by increase the frequency, but it effect the performance (more inefficient). Switch your app to event mode. Create some 'dummy' control in your GUI, and take a look at the GUISetAccelerators function. This way every event is catch when it comes, efficiently and reliability.Is this what you mean by using the Accelerators?$right_dum = GUICtrlCreateDummy() $left_dum = GUICtrlCreateDummy() Dim $keys[2][2] = [["{LEFT}",$left_dum],["{RIGHT}",$right_dum]] GUISetAccelerators($keys) GUICtrlSetOnEvent($right_dum,"_change_direction_right") GUICtrlSetOnEvent($left_dum,"_Change_direction")To animate something without flickering you have to finish drawing on the back buffer and then copy the result (bitmap) to the GUI.Using more than one back buffer make only sense if you need additional operations like rotation whereas the visible graphic handle shouldn't be impacted by the rotation. That means the back buffers will be copied sequentially to the GUI (overlapped).You've helped me a lot so far UEZ and I can't be more thankful but one last question (hopefully) how do you copy the result to the GUI?I tried this but not sure if this is what you mean (it still causes it to flicker)_GDIPlus_GraphicsDrawImageRectRect($hwnd, $backbuffer, 0, 0, 640, 480,0,0,640,480) Link to comment Share on other sites More sharing options...
binhnx Posted June 4, 2015 Share Posted June 4, 2015 Thanks for all the help guys, I've learned a lot in just the past few hours but some things I don't quite get.Is this what you mean by using the Accelerators?$right_dum = GUICtrlCreateDummy() $left_dum = GUICtrlCreateDummy() Dim $keys[2][2] = [["{LEFT}",$left_dum],["{RIGHT}",$right_dum]] GUISetAccelerators($keys) GUICtrlSetOnEvent($right_dum,"_change_direction_right") GUICtrlSetOnEvent($left_dum,"_Change_direction")Yes, and do it also for up and down key, you will see your game will respond to key press more accuracy and smoothly. I tried this but not sure if this is what you mean (it still causes it to flicker)_GDIPlus_GraphicsDrawImageRectRect($hwnd, $backbuffer, 0, 0, 640, 480,0,0,640,480)Not sure why you still get flickering. I try editing some lines and the flickering gone:If $spawned = True Then _GDIPlus_GraphicsDrawLine($backbuffer,$ran_x_line+$x_rect,$ran_y_line+$y_rect,$ran_x_line+$x_rect,$ran_y_line_solid+$y_rect,$pen_barrel) EndIf Sleep(100) _GDIPlus_GraphicsDrawImageRectRect($hwnd, $bitmap, 0, 0, 640, 480, 0, 0, 640, 480) ;_GDIPlus_GraphicsDrawLine($backbuffer_2,0,0,100,100,$pen_body) ;_GDIPlus_GraphicsDrawImageRect($hwnd, $bitmap_2, $x_rect, $y_rect, 2000, 1000) 99 little bugs in the code 99 little bugs! Take one down, patch it around 117 little bugs in the code! Link to comment Share on other sites More sharing options...
gottygolly Posted June 4, 2015 Author Share Posted June 4, 2015 If i edit the code the same way you did I also lose the flickering but then lose the ability to move the barrel around when the "car" moves. I'll keep trying different things and hopefully figure it out soon, thanks for the tip with the accelerator keys! Link to comment Share on other sites More sharing options...
nitekram Posted June 23, 2015 Share Posted June 23, 2015 Any update on this? I am looking to learn more about these functions, and this appears to be very informative. 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now