|
-
Mar 17th, 2003, 07:33 PM
#1
Thread Starter
Fanatic Member
Animati0n over BG, going reaLLy slow
I have a bitmap being animated over a background (bmp). But it goes really slow. I included the code, can someone please check for anything that can be causing it to go sLow (I think its in the bLitter sub)
VB Code:
Option Explicit
Private Type AnimationFrame
Top As Long
Left As Long
End Type
Dim DX As New DirectX7 'dEclare DX7 object, dont forget the 'new'
Dim DD As DirectDraw7
Dim PrimarySurface As DirectDrawSurface7 'The main surface user sEEs
Dim PrimeDesc As DDSURFACEDESC2
Dim OSPbackGround As DirectDrawSurface7 'OffscreenPlain background
Dim BackDesc As DDSURFACEDESC2
Dim OSPsprite As DirectDrawSurface7 'OffscreenpLain sprite
Dim SpriteDesc As DDSURFACEDESC2
Dim Clippa As DirectDrawClipper
Dim rPrime As RECT
Dim rBG As RECT
Dim rSprite As RECT
Dim Frame(3) As AnimationFrame
Dim curFrame As Long
Dim GoGoGo As Boolean
Dim ReturnValue As Long
Dim Temp As Long
Dim bBLT As Boolean 'tells whether to animaTe or not
Dim bINT As Boolean 'True if init is succesfuLL
Private Sub Form_Load()
Me.Height = 5000 'Set form height and width
Me.Width = 5000 'tHats the kid -_-
Init_DX_Stuff 'call this sub to set all variabLes/obj
Do While bBLT = True 'Loop while bBLT is true,
DoEvents
BitBlitter 'This is the main loop, that will animate
DoEvents
Loop
End Sub
Private Sub Init_DX_Stuff()
'DX objects-
Set DD = DX.DirectDrawCreate("")
Call DD.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL)
'Primary----
PrimeDesc.lFlags = DDSD_CAPS
PrimeDesc.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
Set PrimarySurface = DD.CreateSurface(PrimeDesc)
'Background--
BackDesc.lFlags = DDSD_CAPS
BackDesc.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
Set OSPbackGround = DD.CreateSurfaceFromFile(App.Path & "\bg.bmp", BackDesc)
'Sprite------
SpriteDesc.lFlags = DDSD_CAPS
SpriteDesc.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
Set OSPsprite = DD.CreateSurfaceFromFile(App.Path & "\sprite.bmp", SpriteDesc)
'kLipper-----
Set Clippa = DD.CreateClipper(0)
Clippa.SetHWnd Me.hWnd
PrimarySurface.SetClipper Clippa
'CreateTable-
LookUpTable
'variabLes---
bINT = True
bBLT = True
GoGoGo = True
Form1.Show
End Sub
Private Sub BitBlitter()
'Check------
If bINT = False Then Exit Sub
'RectangLes-
Call DX.GetWindowRect(Me.hWnd, rPrime)
rSprite.Top = Frame(curFrame).Top
rSprite.Left = Frame(curFrame).Left
rSprite.Right = rSprite.Left + 36
rSprite.Bottom = rSprite.Top + 62
rBG.Bottom = BackDesc.lHeight
rBG.Right = BackDesc.lWidth
'rBG.Left = BackDesc.lWidth
'rBG.Top = BackDesc.lHeight
'AnimatioN
If DX.TickCount >= Temp + 1000 / 30 Then 'Check to see if Xmilliseconds passed or not
Temp = DX.TickCount
If GoGoGo = True Then
curFrame = curFrame + 1
If curFrame > UBound(Frame) Then
curFrame = UBound(Frame)
GoGoGo = False
End If
Else
curFrame = curFrame - 1
If curFrame < LBound(Frame) Then
curFrame = LBound(Frame)
GoGoGo = True
End If
End If
End If
'BlitterIt--
ReturnValue = OSPbackGround.BltFast(150, 150, OSPsprite, rSprite, DDBLTFAST_WAIT)
ReturnValue = PrimarySurface.Blt(rPrime, OSPbackGround, rBG, DDBLT_WAIT)
End Sub
Private Sub LookUpTable()
Frame(0).Left = 0
Frame(1).Left = 35
Frame(2).Left = 70
Frame(3).Left = 105
End Sub
Private Sub Form_Unload(Cancel As Integer)
bBLT = False
Unload Me
End Sub
-
Mar 18th, 2003, 09:15 PM
#2
Thread Starter
Fanatic Member
CAn someone please check this for me, the bLT sub at least, I dont know whats wrong, I tried a smaller BMP file but it didnt work, both of these are 24bit.. i tried it with a loop at 1secodn interval.. and doEvents all over the place, no luck.
-
Mar 18th, 2003, 09:41 PM
#3
Thread Starter
Fanatic Member
~
Here, I uploaded the project, can anyone *pleasE* help so I can move on.
http://wordbirdturd.tripod.com/Animation_overa_BG.zip
Paste the URL in IE.
-
Mar 18th, 2003, 10:29 PM
#4
Thread Starter
Fanatic Member
Ok ok, I added "Or DDSCAPS_SYSTEMMEMORY" to the background buffer and now its really fast but it flickers a little, how would I fix that? The animation is really smooth now tho, what does that line do?
-
Mar 19th, 2003, 12:21 AM
#5
Addicted Member
LinE
OlD:
That line makes your App use System Memory(RaM), over Video Memory(Video Card). Which usually has more memory available and is alot faster. Check your frame(s). I used to have the frame flickering problem only because I set the frame to a totally white part of the bMP. Other then that you could be doing something wrong. Post the whole thing and I can see.
oK, I remembered how I fixed this when it happened to me. Somewhere between your frame timing and the actual blt'inG your doing something. This is what causes the flickering, maybe you have a DoEvents somewhere, thats what caused the flickering for me. Reorganize the code so it BLT right after the frame timing. This is most likely whats causing it
VB Code:
Do While bBLT = True 'Loop while bBLT is true,
DoEvents
BitBlitter 'This is the main loop, that will animate
DoEvents
Remove the DoEvents before BitBlitter keep the one after that should fix it
Last edited by Sonikku`; Mar 19th, 2003 at 12:34 AM.
Sonikku`- First Days of VB
[vbcode]
Dim Text1.Text as String
[/vbcode]
<Sonikku`> Whats wrong with this code, i keep getting an error about reserved keyword?
<od`Sinchro> LOL!
<Sonikku`> ?
-
Mar 19th, 2003, 12:45 AM
#6
Good Ol' Platypus
It depends. If your CPU is the bottleneck (which it usually is), use Video Memory. If your graphics card is the bottleneck, use System Memory. However, it's more of a bottleneck in terms of memory speed.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Mar 19th, 2003, 11:22 AM
#7
Thread Starter
Fanatic Member
I do not think my videocard/CPU are bottlenecks, I think its somewhere in the software, because Sonikku's examples don't run so slow. uMm, I will remove that dOEvents when I get home. ThanKs.
Sonikku`, "Last edited by Sonikku` on 03-19-2003 at 05:34 AM" why didn't you go to school?
-
Mar 20th, 2003, 12:35 AM
#8
Addicted Member
UM
I tried your example on my pC and others, no flickering problem watsoever. Maybe theres something wrong with your hardware or software?
Sonikku`- First Days of VB
[vbcode]
Dim Text1.Text as String
[/vbcode]
<Sonikku`> Whats wrong with this code, i keep getting an error about reserved keyword?
<od`Sinchro> LOL!
<Sonikku`> ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|