Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Game Programming > DirectX > BltFast


Reply
 
Thread Tools Display Modes
  #1  
Old 02-21-2009, 05:00 PM
wolfstrike's Avatar
wolfstrike wolfstrike is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 297
Default BltFast

how can i convert this into a tiled map?

i want to use BltFast.

everytime i try to make a tiled map (backbuffer) i get errors with graphics, mostly because the size of the total screen changes.
i need the backbuffer larger of course, then tile the images in an array


BackGroundPic is 32x32



Code:
'create the back buffer
    ddsdBackBuffer.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
    ddsdBackBuffer.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
    ddsdBackBuffer.lWidth = SCREENWIDTH
    ddsdBackBuffer.lHeight = SCREENHEIGHT
    Set ddBackBuffer = ddraw.CreateSurface(ddsdBackBuffer)
    rBackBuffer.Bottom = ddsdBackBuffer.lHeight
    rBackBuffer.Right = ddsdBackBuffer.lWidth
    
    'load the background image
    ddsdBackground.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
    ddsdBackground.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
    ddsdBackground.lWidth = SCREENWIDTH
    ddsdBackground.lHeight = SCREENHEIGHT
    Set ddBackground = ddraw.CreateSurfaceFromFile(App.Path & _
        "\BackGroundPic.bmp", ddsdBackground) 
    rBackground.Bottom = ddsdBackground.lHeight
    rBackground.Right = ddsdBackground.lWidth

' dim X as long dim Y as long
' for X = 0 to 16  for Y = 0 to 16
    ddBackBuffer.BltFast x, y, ddBackground, rBackground, _
        DDBLTFAST_WAIT

' next x next y
__________________
The Pho·net·ic Programmer
Reply With Quote
  #2  
Old 02-21-2009, 09:59 PM
AdrianDeAngelis's Avatar
AdrianDeAngelis AdrianDeAngelis is offline
Contributor
 
Join Date: May 2005
Location: Australia
Posts: 548
Default

Well you have two problems going on that I can see

1) in your code you have set ddsdBackground.lWidth = SCREENWIDTH and ddsdBackground.lHeight = SCREENHEIGHT so that when you when you load your 32x32 pixel background image into the surface ddbackground using the ddsdBackground you are actually stretching the entire 32x32 image into a surface the size of your entire screen... your code should read

Code:
ddsdBackground.lWidth = 32 ddsdBackground.lHeight = 32 Set ddBackground = ddraw.CreateSurfaceFromFile(App.Path & _ "\BackGroundPic.bmp", ddsdBackground)

or you should not enter a value for the height and width before you start (or make them both zero) so that the size of the picture that you are loading causes the height and width of the ddsd to be resized.

2) 32x16 = 512, of course at the moment you are trying to blit too large an image onto the screen but depending upon what resolution you are working at even when you do make the change you might be trying to blit an image out of bounds. You can't blit out of the source image or destination image bounds so you need to add a clipping routine to resize your source rect if you try to blit out of bounds.

Code:
With rBackground If Y < 0 Then .Top = .Top - Y: Y = 0 If Y + .Bottom > SCREENHEIGHT Then .Bottom = .Bottom - (Y + .Bottom - SCREENHEIGHT) End If If X < 0 Then .Left = .Left - X: X = 0 If X + .Right > SCREENWIDTH Then .Right = .Right - (X + .Right - SCREENWIDTH) End If End With

Now what this means is that you are going to have to reset your source rect every time you try to blit an image, there really isn't any way around that... What would be best is to load all of your images (including your backbuffer) as an array of surfaces or DDSD... you could use a custom type like this:

Code:
'direct draw surface type Public Type DDImage ID As PicInfo ddsd As DDSURFACEDESC2 nSurf As DirectDrawSurface7 End Type

and then instead of having to write the blitting routine for every new image, make a reusable function that lets you blit from one array member to the other with its own clipping routine built in.
__________________
Automation error... What do you mean automation error you %#@*&!$ thing!

Star Admiral: 3D tactical space sim *** New Version 0.38 10/01/09 ***
Damage, shields and special weapons systems

Last edited by AdrianDeAngelis; 02-21-2009 at 10:05 PM.
Reply With Quote
  #3  
Old 02-22-2009, 01:05 AM
wolfstrike's Avatar
wolfstrike wolfstrike is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 297
Default

thanks.



i'm looking for an example of how to load an array of tiles instead of one bitmap
__________________
The Pho·net·ic Programmer
Reply With Quote
  #4  
Old 02-22-2009, 03:44 AM
AdrianDeAngelis's Avatar
AdrianDeAngelis AdrianDeAngelis is offline
Contributor
 
Join Date: May 2005
Location: Australia
Posts: 548
Default

Quote:
Originally Posted by wolfstrike View Post
thanks.



i'm looking for an example of how to load an array of tiles instead of one bitmap
It is exactly the same as loading a bitmap into a single surface, say you used an array of Pic using the example DDimage type above then

DDSD substitutes as pic(arrayindex).ddsd
Surface substitutes as pic(arrayindex).nsurf

when you want to use your graphics subs you pass the array index of the surfaces (NOT the surfaces themselves) that you want to work with to your routine. You can also create a set of constants such as backbuffer = 0 to name your surfaces and pass those to your routine. Remember there is nothing special about the backbuffer surface, the only difference between it and any other DD surfaces is the flags that you set when creating it in the backbuffer's ddsd, hence your backbuffer can be a part of your array.
__________________
Automation error... What do you mean automation error you %#@*&!$ thing!

Star Admiral: 3D tactical space sim *** New Version 0.38 10/01/09 ***
Damage, shields and special weapons systems
Reply With Quote
  #5  
Old 03-08-2009, 12:22 AM
wolfstrike's Avatar
wolfstrike wolfstrike is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 297
Default

usually i don't hack demos, but i need to learn directdraw.
i understand most of it farely well , but it's hard for me to convert this code because i've never seen a demo,
and i can't find one on the net.

i was able to convert the background to 32x32 tiles, but when the sprites run across i get visual errors.
so i guess my problem is in the 'refresh' stage of the code.

i was also able to change the transparent color.

here's the code before i changed it
this code loads a background and a sprite into memory
Code:
Option Explicit
Option Base 0

'Windows API functions and structures
Private Declare Function GetTickCount _
    Lib "kernel32" () As Long

'program constants
Const SCREENWIDTH As Long = 640
Const SCREENHEIGHT As Long = 480
Const MAXFRAMERATE As Long = 100
Const NUMSPRITES As Long = 30

'program controls
Dim WithEvents Picture1 As PictureBox

'DirectDraw variables
Dim objDX As DirectX7
Dim ddraw As DirectDraw7
Dim objDDClip As DirectDrawClipper
Private ddcKey As DDCOLORKEY

'primary display surface variables
Dim ddScreen As DirectDrawSurface7
Private ddsdScreen As DDSURFACEDESC2
Private rScreen As RECT

'double buffer variables
Dim ddBackBuffer As DirectDrawSurface7
Private ddsdBackBuffer As DDSURFACEDESC2
Dim rBackBuffer As RECT

'background image variables
Dim ddBackground As DirectDrawSurface7
Private ddsdBackground As DDSURFACEDESC2
Dim rBackground As RECT

'sprite variables
Dim ddSprites(NUMSPRITES) As DirectDrawSurface7
Dim SpriteX(NUMSPRITES) As Long
Dim SpriteY(NUMSPRITES) As Long
Dim SpeedX(NUMSPRITES) As Long
Dim SpeedY(NUMSPRITES) As Long
Private ddsdSprite As DDSURFACEDESC2
Dim rSprite As RECT

'program variables
Dim rTemp As RECT
Dim bRunning As Boolean
Dim n As Long

Private Sub Form_Load()
    Static lStartTime As Long
    Static lCounter As Long
    Static lNewTime As Long
    
    bRunning = True
    Randomize GetTickCount
    
    'set up the main form
    With Form1
        .Width = SCREENWIDTH * Screen.TwipsPerPixelX
        .Height = SCREENHEIGHT * Screen.TwipsPerPixelY
        .AutoRedraw = False
        .ClipControls = False
        .KeyPreview = True
        .ScaleMode = 3
        .BorderStyle = 1
        .Show
    End With

    'create the PictureBox control
    Set Picture1 = Controls.Add("VB.PictureBox", "Picture1")
    With Picture1
        .AutoRedraw = False
        .BorderStyle = 1
        .ClipControls = False
        .ScaleMode = 3
        .BackColor = RGB(0, 0, 0)
        .Left = 0
        .Top = 0
        .Width = Form1.ScaleWidth
        .Height = Form1.ScaleHeight
        .Visible = True
    End With

    'create the DirectX object
    Set objDX = New DirectX7
    
    'create the DirectDraw object
    Set ddraw = objDX.DirectDrawCreate("")

    'set up primary display surface
    ddraw.SetCooperativeLevel Picture1.hWnd, DDSCL_NORMAL
    ddsdScreen.lFlags = DDSD_CAPS
    ddsdScreen.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
    ddsdScreen.lWidth = SCREENWIDTH
    ddsdScreen.lHeight = SCREENHEIGHT
    Set ddScreen = ddraw.CreateSurface(ddsdScreen)
    
    'set surface rectangle
    rScreen.Bottom = ddsdScreen.lHeight
    rScreen.Right = ddsdScreen.lWidth
    
    'create the clipper object
    Set objDDClip = ddraw.CreateClipper(0)
    objDDClip.SetHWnd Picture1.hWnd
    ddScreen.SetClipper objDDClip
    
    'create the back buffer
    ddsdBackBuffer.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
    ddsdBackBuffer.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
    ddsdBackBuffer.lWidth = SCREENWIDTH
    ddsdBackBuffer.lHeight = SCREENHEIGHT
    Set ddBackBuffer = ddraw.CreateSurface(ddsdBackBuffer)
    rBackBuffer.Bottom = ddsdBackBuffer.lHeight
    rBackBuffer.Right = ddsdBackBuffer.lWidth
    
    'load the background image
    ddsdBackground.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
    ddsdBackground.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
    ddsdBackground.lWidth = SCREENWIDTH
    ddsdBackground.lHeight = SCREENHEIGHT
    Set ddBackground = ddraw.CreateSurfaceFromFile(App.Path & _
        "\blueyellow.bmp", ddsdBackground)
    rBackground.Bottom = ddsdBackground.lHeight
    rBackground.Right = ddsdBackground.lWidth
    ddBackBuffer.BltFast 0, 0, ddBackground, rBackground, _
        DDBLTFAST_WAIT
    
    'set up the sprite information
    ddsdSprite.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
    ddsdSprite.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
    ddsdSprite.lWidth = 64
    ddsdSprite.lHeight = 64
    ddcKey.low = 0
    ddcKey.high = 0
    
    'load the sprites
    For n = 0 To NUMSPRITES
        Set ddSprites(n) = ddraw.CreateSurfaceFromFile(App.Path & _
            "\directx.bmp", ddsdSprite)
        rSprite.Bottom = ddsdSprite.lHeight
        rSprite.Right = ddsdSprite.lWidth
        SpriteX(n) = Random(SCREENWIDTH - ddsdSprite.lWidth)
        SpriteY(n) = Random(SCREENHEIGHT - ddsdSprite.lHeight)
        Do Until SpeedX(n) <> 0
            SpeedX(n) = Random(6) - 3
        Loop
        Do Until SpeedY(n) <> 0
            SpeedY(n) = Random(6) - 3
        Loop
        ddSprites(n).SetColorKey DDCKEY_SRCBLT, ddcKey
    Next n
    
    'main game loop
    Do While bRunning
        lCounter = GetTickCount - lStartTime
        If lCounter > lNewTime Then
            'update game display
            Game_Update lCounter
            'update frame count
            lNewTime = lCounter + 1000 / MAXFRAMERATE
        End If
        DoEvents
    Loop
    
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 27 Then Shutdown
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Shutdown
End Sub

Private Sub Form1_Click()
    Shutdown
End Sub

Private Sub Picture1_Click()
    Shutdown
End Sub

Private Sub Shutdown()
    bRunning = False
    Form1.Hide
    ddraw.RestoreDisplayMode
    ddraw.SetCooperativeLevel Picture1.hWnd, DDSCL_NORMAL
    Set ddraw = Nothing
    Set objDX = Nothing
    End
End Sub

Public Function Random(ByVal lNum As Long) As Long
    Random = CLng(lNum * Rnd)
End Function

Public Sub Game_Update(ByVal MS As Long)
    Static lTimer As Long
    Static lStart As Long
    Static lCounter As Long

    'start counting draw time
    lStart = GetTickCount

    'erase sprites
    For n = 0 To NUMSPRITES
        rTemp.Left = SpriteX(n)
        rTemp.Top = SpriteY(n)
        rTemp.Right = rTemp.Left + ddsdSprite.lWidth
        rTemp.Bottom = rTemp.Top + ddsdSprite.lHeight
        ddBackBuffer.BltFast SpriteX(n), SpriteY(n), ddBackground, _
            rTemp, DDBLTFAST_WAIT
    Next n
    
    'move and draw the sprites
    For n = 0 To NUMSPRITES
        'update X position
        SpriteX(n) = SpriteX(n) + SpeedX(n)
        If SpriteX(n) < 1 Then
            SpeedX(n) = -SpeedX(n)
            SpriteX(n) = 1
        ElseIf SpriteX(n) + ddsdSprite.lWidth > SCREENWIDTH Then
            SpeedX(n) = -SpeedX(n)
            SpriteX(n) = SCREENWIDTH - ddsdSprite.lWidth - 1
        End If

        'update Y position
        SpriteY(n) = SpriteY(n) + SpeedY(n)
        If SpriteY(n) < 1 Then
            SpeedY(n) = -SpeedY(n)
            SpriteY(n) = 1
        ElseIf SpriteY(n) + ddsdSprite.lHeight > SCREENHEIGHT Then
            SpeedY(n) = -SpeedY(n)
            SpriteY(n) = SCREENHEIGHT - ddsdSprite.lHeight - 1
        End If

        'draw the sprite
        rTemp.Left = SpriteX(n)
        rTemp.Top = SpriteY(n)
        rTemp.Right = SpriteX(n) + ddsdSprite.lWidth
        rTemp.Bottom = SpriteY(n) + ddsdSprite.lHeight
        ddBackBuffer.Blt rTemp, ddSprites(n), rSprite, _
            DDBLT_WAIT Or DDBLT_KEYSRC
    Next n
    
    'copy double buffer to the screen
    objDX.GetWindowRect Picture1.hWnd, rScreen
    ddScreen.Blt rScreen, ddBackBuffer, rBackBuffer, DDBLT_WAIT

    'count the frames per second
    If MS > lTimer + 1000 Then
        lStart = GetTickCount - lStart
        Form1.Caption = "FPS = " & lCounter & ", MS = " & lStart
        lTimer = MS
        lCounter = 0
    Else
        lCounter = lCounter + 1
    End If
End Sub
__________________
The Pho·net·ic Programmer
Reply With Quote
  #6  
Old 03-10-2009, 06:52 PM
wolfstrike's Avatar
wolfstrike wolfstrike is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 297
Default

nobody has any suggestions?
__________________
The Pho·net·ic Programmer
Reply With Quote
  #7  
Old 03-13-2009, 03:58 PM
Cerian Knight's Avatar
Cerian Knight Cerian Knight is offline
Multi-Technologist

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 3,040
Default

I ran this code (post#5) and the only problem I see is periodic stuttering of movement, maybe due to the way GetTickCount values are used. What specific issues are you seeing?
__________________
This signature could be yours (see inside for details).
Reply With Quote
  #8  
Old 03-13-2009, 04:46 PM
wolfstrike's Avatar
wolfstrike wolfstrike is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 297
Default

thanks for responding to my post.

i have no problems with runing the code on my computer.

i'm new to Directdraw7.

instead of having one large picture as background, i'm trying to convert it to a tiled background using BltFast.

i was able to make it a tiled background, but when the sprites move across the screen, they stopped being erased.

...so i'm trying to convert this into a tiled background and have it refresh properly.





here's the code after i tried to change it.
(i use the spritePic as the tile for the background)


this is a mess i know....


Quote:
'----------------------------------------------------------------------
' Visual Basic Game Programming With DirectX
' Chapter 10 : Diving Into DirectDraw
' DDWindow Source Code File
'----------------------------------------------------------------------

Option Explicit
Option Base 0

'Windows API functions and structures
Private Declare Function GetTickCount _
Lib "kernel32" () As Long

'program constants
Const SCREENWIDTH As Long = 640
Const SCREENHEIGHT As Long = 480
Const MAXFRAMERATE As Long = 100
Const NUMSPRITES As Long = 2

'program controls
Dim WithEvents Picture1 As PictureBox

'DirectDraw variables
Dim objDX As DirectX7
Dim ddraw As DirectDraw7
Dim objDDClip As DirectDrawClipper
Private ddcKey As DDCOLORKEY

'primary display surface variables
Dim ddScreen As DirectDrawSurface7
Private ddsdScreen As DDSURFACEDESC2
Private rScreen As RECT

'double buffer variables
Dim ddBackBuffer As DirectDrawSurface7
Private ddsdBackBuffer As DDSURFACEDESC2
Dim rBackBuffer As RECT

'background image variables
Dim ddBackground(1000) As DirectDrawSurface7
Private ddsdBackground As DDSURFACEDESC2
Dim rBackground As RECT

'sprite variables
Dim ddSprites(NUMSPRITES) As DirectDrawSurface7
Dim SpriteX(NUMSPRITES) As Long
Dim SpriteY(NUMSPRITES) As Long
Dim SpeedX(NUMSPRITES) As Long
Dim SpeedY(NUMSPRITES) As Long
Private ddsdSprite As DDSURFACEDESC2
Dim rSprite As RECT

'program variables
Dim rTemp As RECT
Dim bRunning As Boolean
Dim n As Long

Private Sub Form_Load()
Static lStartTime As Long
Static lCounter As Long
Static lNewTime As Long
Dim X As Integer
Dim Y As Integer
Dim NUM As Integer

bRunning = True
Randomize GetTickCount

'set up the main form
With Form1
.Width = SCREENWIDTH * Screen.TwipsPerPixelX
.Height = SCREENHEIGHT * Screen.TwipsPerPixelY
.AutoRedraw = False
.ClipControls = False
.KeyPreview = True
.ScaleMode = 3
.BorderStyle = 1
.Show
End With

'create the PictureBox control
Set Picture1 = Controls.Add("VB.PictureBox", "Picture1")
With Picture1
.AutoRedraw = False
.BorderStyle = 1
.ClipControls = False
.ScaleMode = 3
.BackColor = RGB(0, 0, 0)
.Left = 20
.Top = 20
.Width = Form1.ScaleWidth - 40
.Height = Form1.ScaleHeight - 40
.Visible = True
End With

'create the DirectX object
Set objDX = New DirectX7

'create the DirectDraw object
Set ddraw = objDX.DirectDrawCreate("")

'set up primary display surface
ddraw.SetCooperativeLevel Picture1.hWnd, DDSCL_NORMAL
ddsdScreen.lFlags = DDSD_CAPS
ddsdScreen.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
ddsdScreen.lWidth = SCREENWIDTH
ddsdScreen.lHeight = SCREENHEIGHT
Set ddScreen = ddraw.CreateSurface(ddsdScreen)

'set surface rectangle
rScreen.Bottom = ddsdScreen.lHeight
rScreen.Right = ddsdScreen.lWidth

'create the clipper object
Set objDDClip = ddraw.CreateClipper(0)
objDDClip.SetHWnd Picture1.hWnd
ddScreen.SetClipper objDDClip

'create the back buffer
ddsdBackBuffer.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
ddsdBackBuffer.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
ddsdBackBuffer.lWidth = 680
ddsdBackBuffer.lHeight = 460
Set ddBackBuffer = ddraw.CreateSurface(ddsdBackBuffer)
rBackBuffer.Bottom = 0
rBackBuffer.Right = 0

'load the background image
ddsdBackground.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
ddsdBackground.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
ddsdBackground.lWidth = 32
ddsdBackground.lHeight = 32
For Y = 0 To 10
For X = 0 To 10
n = n + 1
Set ddBackground(0) = ddraw.CreateSurfaceFromFile(App.Path & _
"\SpritePic.bmp", ddsdBackground) ' BackGroundPic
ddBackBuffer.BltFast X * 32, Y * 32, ddBackground(0), rBackground, _
DDBLTFAST_WAIT

Next X
Next Y



'set up the sprite information
ddsdSprite.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
ddsdSprite.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
ddsdSprite.lWidth = 64
ddsdSprite.lHeight = 64
ddcKey.low = vbWhite
ddcKey.high = vbWhite

'load the sprites
For n = 0 To NUMSPRITES
Set ddSprites(n) = ddraw.CreateSurfaceFromFile(App.Path & _
"\SpritePic.bmp", ddsdSprite)
rSprite.Bottom = ddsdSprite.lHeight
rSprite.Right = ddsdSprite.lWidth
SpriteX(n) = Random(SCREENWIDTH - ddsdSprite.lWidth)
SpriteY(n) = Random(SCREENHEIGHT - ddsdSprite.lHeight)
Do Until SpeedX(n) <> 0
SpeedX(n) = Random(6) - 3
Loop
Do Until SpeedY(n) <> 0
SpeedY(n) = Random(6) - 3
Loop
ddSprites(n).SetColorKey DDCKEY_SRCBLT, ddcKey
Next n

'main game loop
Do While bRunning
lCounter = GetTickCount - lStartTime
If lCounter > lNewTime Then
'update game display
Game_Update lCounter
'update frame count
lNewTime = lCounter + 1000 / MAXFRAMERATE
End If
DoEvents
Loop

End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 27 Then Shutdown
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Shutdown
End Sub

Private Sub Form1_Click()
Shutdown
End Sub

Private Sub Picture1_Click()
Shutdown
End Sub

Private Sub Shutdown()
bRunning = False
Form1.Hide
ddraw.RestoreDisplayMode
ddraw.SetCooperativeLevel Picture1.hWnd, DDSCL_NORMAL
Set ddraw = Nothing
Set objDX = Nothing
End
End Sub

Public Function Random(ByVal lNum As Long) As Long
Random = CLng(lNum * Rnd)
End Function

Public Sub Game_Update(ByVal MS As Long)
Static lTimer As Long
Static lStart As Long
Static lCounter As Long

'start counting draw time
lStart = GetTickCount

'erase sprites
For n = 0 To NUMSPRITES
rTemp.Left = SpriteX(n)
rTemp.Top = SpriteY(n)
rTemp.Right = rTemp.Left + ddsdSprite.lWidth
rTemp.Bottom = rTemp.Top + ddsdSprite.lHeight
ddBackBuffer.BltFast SpriteX(n), SpriteY(n), ddBackground(0), _
rTemp, DDBLTFAST_WAIT
Next n

'move and draw the sprites
For n = 0 To NUMSPRITES
'update X position
SpriteX(n) = SpriteX(n) + SpeedX(n)
If SpriteX(n) < 1 Then
SpeedX(n) = -SpeedX(n)
SpriteX(n) = 1
ElseIf SpriteX(n) + ddsdSprite.lWidth > SCREENWIDTH Then
SpeedX(n) = -SpeedX(n)
SpriteX(n) = SCREENWIDTH - ddsdSprite.lWidth - 1
End If

'update Y position
SpriteY(n) = SpriteY(n) + SpeedY(n)
If SpriteY(n) < 1 Then
SpeedY(n) = -SpeedY(n)
SpriteY(n) = 1
ElseIf SpriteY(n) + ddsdSprite.lHeight > SCREENHEIGHT Then
SpeedY(n) = -SpeedY(n)
SpriteY(n) = SCREENHEIGHT - ddsdSprite.lHeight - 1
End If

'draw the sprite
rTemp.Left = SpriteX(n)
rTemp.Top = SpriteY(n)
rTemp.Right = SpriteX(n) + ddsdSprite.lWidth
rTemp.Bottom = SpriteY(n) + ddsdSprite.lHeight
ddBackBuffer.Blt rTemp, ddSprites(n), rSprite, _
DDBLT_WAIT Or DDBLT_KEYSRC
Next n

'copy double buffer to the screen
objDX.GetWindowRect Picture1.hWnd, rScreen
ddScreen.Blt rScreen, ddBackBuffer, rBackBuffer, DDBLT_WAIT

'count the frames per second
If MS > lTimer + 1000 Then
lStart = GetTickCount - lStart
Form1.Caption = "FPS = " & lCounter & ", MS = " & lStart
lTimer = MS
lCounter = 0
Else
lCounter = lCounter + 1
End If
End Sub
__________________
The Pho·net·ic Programmer

Last edited by wolfstrike; 03-13-2009 at 05:20 PM.
Reply With Quote
  #9  
Old 03-14-2009, 02:44 PM
Cerian Knight's Avatar
Cerian Knight Cerian Knight is offline
Multi-Technologist

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 3,040
Default

During erase, the tiles are not offset to the position of the sprite. I'm not sure if it would be better to create a 2x2 tile and offset into it or use multiple BltFast calls for each portion of a tile that is covered. If the tiles are the same, the former makes more sense to me.
__________________
This signature could be yours (see inside for details).
Reply With Quote
  #10  
Old 03-29-2009, 02:45 AM
wolfstrike's Avatar
wolfstrike wolfstrike is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 297
Default

you know, DirectX really isn't that bad...

or should i say, DirectDraw


i'm pulling 64 FPS out of a program i had about 25 FPS in Bitblt



...and after a while, DirectDraw starts making a little sense.
__________________
The Pho·net·ic Programmer
Reply With Quote
  #11  
Old 03-29-2009, 05:13 PM
DarkEnergy's Avatar
DarkEnergy DarkEnergy is offline
Newcomer
 
Join Date: Dec 2008
Posts: 24
Default

I think that there is a difference between just memorizing how to do DirectX and actually truly understand what it is doing. It took me a long time to actually learn how to do my own code in DirectX and not just memorize what to do. Once you get the hang of it, however, it can be a great tool and has some nice benefits over BitBlt.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:

Powered by liquidweb