Jump to content
Sign in to follow this  
BillLuvsU

Using GDIPlus efficiently

Recommended Posts

BillLuvsU

Ok, so I recently start playing around with GDIPlus, with an explanation or two on the basic theory. How it was explained to me, was you load the correct background section into a bitmap, and then overlay the characters, items etc that you need and send the completed image to our graphics control. When playing around with the functions included in the autoit library however, it doesn't seem to quite work like that. Using the excellent mario game as a reference point. The only way i could see that made sense was constructing your frame on the graphics control. However, when I attempted to draw the background and the character directly on to my GUI, it causes a flashing effect (I'm assuming this is caused by real time lag between the two draw functions). So, if the lag between two draw functions is enough to cause a flash, I can't see extending the code making it any better. I saw somthing in the Mario code using _WinAPI_RedrawWindow but I'm not sure how that works in with the GDIPlus commands. My code is below, any help or ideas would be appreciated.

;//////////////////   INITIATION
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#Include <Misc.au3>
#include <WindowsConstants.au3>



Dim $dll_user32 = DllOpen("user32.dll")
Dim $x =300
Dim $y =300

Dim $speed = 5




;////////////////// GUI CREATION

;Main GUI
$h_GUI_main = GUICreate( "Battle of Destiny", 800, 600 )
GUISetState( )

;Character
$h_GUI_character = GUICreate("", 34, 47, 383, 277, $WS_CHILD, 0, $h_GUI_main )
GUISetState( )



_GDIPlus_Startup ()

; Draw bitmap to GUI
$hBitmap = _GDIPlus_BitmapCreateFromFile (@ScriptDir& "\Images\map_01.bmp")
$h_link_ref = _GDIPlus_BitmapCreateFromFile (@ScriptDir& "\Images\characters\link.png")
MsgBox(0,"",$hBitmap)
Dim $h_graphic_main = _GDIPlus_GraphicsCreateFromHWND ($h_GUI_main)
Dim $h_graphic_character = _GDIPlus_GraphicsCreateFromHWND ($h_GUI_character)
Dim $hClone = _GDIPlus_BitmapCloneArea ($hBitmap, 0, 0, 800, 600, $GDIP_PXF24RGB)
_GDIPlus_DrawImagePoints($h_graphic_main, $hClone, 0, 0, 800, 0, 0, 600)







;//////////////////  MAIN LOOP
$msg = 0
Dim $move = 0

While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg( )

    $move = 0
    If _IsPressed("25", $dll_user32) Then Left( )
    If _IsPressed("26", $dll_user32) Then Up( )
    If _IsPressed("27", $dll_user32) Then Right( )
    If _IsPressed("28", $dll_user32) Then Down( )
    $h_frame = _GDIPlus_BitmapCloneArea ($hBitmap, $x, $y, 800, 600, $GDIP_PXF24RGB)
    $h_hero = _GDIPlus_BitmapCloneArea ($h_link_ref, 0, 0, 34, 47, $GDIP_PXF24RGB)

    If $move = 1 Then _GDIPlus_GraphicsDrawImage($h_graphic_main, $h_frame, 0, 0)
    _GDIPlus_GraphicsDrawImage($h_graphic_character, $h_hero, 0, 0)


    ;Sleep ( 50)
WEnd

_GDIPlus_ShutDown ()
    _GDIPlus_ImageDispose ($h_frame)
    _WinAPI_DeleteObject ($hBitmap)








;//////////////////////   FUNCTIONS
Func Right( )
    $x = $x + $speed
    $move = 1
EndFunc

Func Down( )
    $y = $y + $speed
    $move = 1
EndFunc

Func Up( )
    $y = $y - $speed
    $move = 1
EndFunc

Func Left( )
    $x = $x - $speed
    $move = 1
EndFunc

Edit: looking at my own code I remembered that I changed around how it works, I tried using a separate GUI to see If that would stop the flashing, but still no luck. Sorry for the crappy coding :x.

Edited by BillLuvsU

[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Share this post


Link to post
Share on other sites
BillLuvsU

Ah, a million thanks Zedna. :x Exactly what I was looking for.


[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.