Hailo. I'm trying to create sprites using bitblt but have no idea what to do. So far I have used bitblt to create a scrolling background, but I don't think I understand bitblt enough to create, for example, a walking animation.
So, any good tutorial links/sample code/pseudocode would be great
Thanks for the reply! I have gotten my sprites working, now I'm trying to workout how to move the animation around the screen using the arrow keys. This is my code so far:
Code:
Option Explicit
Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
Dim HeroineY As Integer
Dim Running As Boolean 'To know if the game is running
Const FPS As Double = 61.3 'Frames Per Second
Private Sub Form_Load()
Me.Show 'Display main window
Running = True
GameLoop 'Start the loop
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode < 40 Then keyarray(KeyCode) = True 'remember the key is down
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode < 40 Then keyarray(KeyCode) = False 'remember the key is up
End Sub
Private Sub GameLoop()
Dim cTimer As Currency 'Time of last tick
Dim cTimer2 As Currency 'Current time
Dim Freq As Currency 'Frequency of Counter
Dim Interval As Double 'Time of each frame
Static animFrame As Integer
'Dim HeroineY As Integer
QueryPerformanceFrequency Freq 'Get Frequency
Interval = 80
'Freq / FPS 'Calculate interval based on FPS and Frequency
While Running 'Start loop
QueryPerformanceCounter cTimer2 'Get current time
If cTimer2 >= cTimer + Interval Then 'Check if it's time to run code
Me.Caption = "FPS: " & Format(Round(Freq / (cTimer2 - cTimer), 1), "0.0") 'Display FPS on screen
QueryPerformanceCounter cTimer 'Get time for later use
BitBlt Me.hDC, 0, 0, Me.Width, Me.Height, picBackground.hDC, BGCut, 0, vbSrcCopy
BGCut = BGCut + 5
Second
'If keyarray(37) = True Then
'HeroineY = HeroineY + 1
BitBlt Form1.hDC, _
0, HeroineY, _
80, 66, _
picSource.hDC, _
animFrame * -2, 66, _
vbSrcAnd
BitBlt Form1.hDC, _
0, HeroineY, _
80, 65, _
picSource.hDC, _
animFrame * 75, -2, _
vbSrcPaint
animFrame = animFrame + 1
If animFrame = 3 Then animFrame = 1
'End If
'Enter code here
End If
DoEvents
Wend
End Sub
Private Sub Form_Unload(Cancel As Integer)
Running = False 'Exit loop
End Sub
Private Sub Second()
If keyarray(37) = True Then
HeroineY = HeroineY + 10
End If
End Sub
It's really just a kind of compilation of code I've found from tutorials.
I've tried many different ways of moving the animation across the screen, besides the one you see here, but either they result in the animation playing in its original spot without movement, or it becomes invisible and all I can see is the scrolling background. Yet if I place in the loop "HeroineY = HeroineY + 10" not in an If statement, the animation moves down the screen.
Any suggestions would be very much appreciated thank you!