F
Fab'
Hello!
Excuse me for my english level because I'm french!
This message is post to : microsoft.public.vb.winapi.graphics,
microsoft.public.vb.general.discussion, microsoft.public.project.vba
My computer confuguration : WinMe, Excel 2000.
I play with the api's gdi to try to create a game engine, I'm a fool, I
know but I want to try this fool project!
A part of the code is in the end on this message.
I create a VBAProject with a form intitulate "G_Screen".
The game displays in this form.
I have a background and a sprite (with differents frames to animate)
which are load in memory.
I use the api "SetTimer" to do a cycle sub to display the animation sprite.
I use a double buffering, but it's strange because I have to paint twice
from offscreen'dc to form'dc if I want to displays the animation. If I
try to draw in once time I see only the sprite but with no transparence!
Help me please!
Thanks!
'------------------------------------
The code of form initialize
'Acquisition des contextes de périphérique graphique
hWndform = GetActiveWindow()
hDCform = GetDC(hWndform)
'Création d'un Offscreen compatible avec la form
hDCOffscreen = CreateCompatibleDC(0&)
hDCOffscreenBmp = CreateCompatibleBitmap(hOffscreenDC, 0, 0)
Call SelectObject(hDCOffscreen, hDCOffscreenBmp)
'Chargement en mémoire du background
hBackgnd = LoadImage(0&, CheminInstall + "Background_sonic.bmp", 0, 0,
0, &H10)
'Chargement en mémoire du sprite
With Sonic
hSprite = LoadImage(0&, CheminInstall + "Sonic_run.bmp", 0, 0, 0, &H10)
End With
Call SetTimer(hWndform, 0, ImagDelai, AddressOf G_Timer)
'------------------------------------
The code of timer procedure :
Sub G_Timer(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As
Long, ByVal lpTimerFunc As Long)
DoEvents
'Acquisition des contextes de périphérique graphique
'Hwndform = GetActiveWindow()
'Hdcform = GetDC(Hwndform)
'dessin sur l'offscreen du background
Call SelectObject(hOffscreenDC, hBackgnd)
Call BitBlt(hOffscreenDC, 0, 0, 640, 480, hBackgnd, 0, 0, SRCCOPY)
'dessin de l'offscreen du background sur la form
Call BitBlt(Hdcform, 0, 0, G_Screen.Width * 1.33, G_Screen.Height *
1.33, hOffscreenDC, 0, 0, SRCCOPY)
'dessin sur l'offscreen du fantôme avec transparence
Sonic_f = GetPosFrameX(Sonic, False)
Call SelectObject(hOffscreenDC, hSprite)
Call TransparentBlt(hOffscreenDC, 0, 0, 36 * 1.5, 39 * 1.5, hSprite,
Sonic_f, 0, 36, 39, vbWhite)
'dessin de l'offscreen du fantôme sur la form
Call TransparentBlt(Hdcform, t, 100, 36 * 1.5, 39 * 1.5, hOffscreenDC,
Sonic_f, 0, 36, 39, vbWhite)
Call ReleaseDC(Hwndform, Hdcform)
End Sub
Excuse me for my english level because I'm french!
This message is post to : microsoft.public.vb.winapi.graphics,
microsoft.public.vb.general.discussion, microsoft.public.project.vba
My computer confuguration : WinMe, Excel 2000.
I play with the api's gdi to try to create a game engine, I'm a fool, I
know but I want to try this fool project!
A part of the code is in the end on this message.
I create a VBAProject with a form intitulate "G_Screen".
The game displays in this form.
I have a background and a sprite (with differents frames to animate)
which are load in memory.
I use the api "SetTimer" to do a cycle sub to display the animation sprite.
I use a double buffering, but it's strange because I have to paint twice
from offscreen'dc to form'dc if I want to displays the animation. If I
try to draw in once time I see only the sprite but with no transparence!
Help me please!
Thanks!
'------------------------------------
The code of form initialize
'Acquisition des contextes de périphérique graphique
hWndform = GetActiveWindow()
hDCform = GetDC(hWndform)
'Création d'un Offscreen compatible avec la form
hDCOffscreen = CreateCompatibleDC(0&)
hDCOffscreenBmp = CreateCompatibleBitmap(hOffscreenDC, 0, 0)
Call SelectObject(hDCOffscreen, hDCOffscreenBmp)
'Chargement en mémoire du background
hBackgnd = LoadImage(0&, CheminInstall + "Background_sonic.bmp", 0, 0,
0, &H10)
'Chargement en mémoire du sprite
With Sonic
hSprite = LoadImage(0&, CheminInstall + "Sonic_run.bmp", 0, 0, 0, &H10)
End With
Call SetTimer(hWndform, 0, ImagDelai, AddressOf G_Timer)
'------------------------------------
The code of timer procedure :
Sub G_Timer(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As
Long, ByVal lpTimerFunc As Long)
DoEvents
'Acquisition des contextes de périphérique graphique
'Hwndform = GetActiveWindow()
'Hdcform = GetDC(Hwndform)
'dessin sur l'offscreen du background
Call SelectObject(hOffscreenDC, hBackgnd)
Call BitBlt(hOffscreenDC, 0, 0, 640, 480, hBackgnd, 0, 0, SRCCOPY)
'dessin de l'offscreen du background sur la form
Call BitBlt(Hdcform, 0, 0, G_Screen.Width * 1.33, G_Screen.Height *
1.33, hOffscreenDC, 0, 0, SRCCOPY)
'dessin sur l'offscreen du fantôme avec transparence
Sonic_f = GetPosFrameX(Sonic, False)
Call SelectObject(hOffscreenDC, hSprite)
Call TransparentBlt(hOffscreenDC, 0, 0, 36 * 1.5, 39 * 1.5, hSprite,
Sonic_f, 0, 36, 39, vbWhite)
'dessin de l'offscreen du fantôme sur la form
Call TransparentBlt(Hdcform, t, 100, 36 * 1.5, 39 * 1.5, hOffscreenDC,
Sonic_f, 0, 36, 39, vbWhite)
Call ReleaseDC(Hwndform, Hdcform)
End Sub