PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Efficiency of moving sprites? (BitBlt and image controls)-VBForums

View Poll Results: How should I add and blit from images?

Voters
4. You may not vote on this poll
  • 10 million picture boxes on the game form, with all the different images

    0 0%
  • LoadPicture() into a single picture box, each time a new image is needed

    0 0%
  • Copying pictures from the images form into a single box, each time I need them

    1 25.00%
  • Blitting straight from the images form

    3 75.00%
Results 1 to 12 of 12

Thread: Efficiency of moving sprites? (BitBlt and image controls)

  1. #1

    Thread Starter
    New Member Son of Makuta's Avatar
    Join Date
    Sep 2007
    Posts
    14

    Efficiency of moving sprites? (BitBlt and image controls)

    Hi everybody. I'm working on a space shooter with a pile of enemies, bullets, etc. As of now they're all image controls but I'm going to use BitBlt, and custom data types to create non-existent controls (so I can just set some variables to be the top, left, height and/or width etc) and then blit a sprite to the correct location.

    Anyway, I have the main game form and a form full of image controls containing a repository of picture boxes holding all the images needed for the game (a way around LoadPicture before I discovered 'AppPath'). I've got four options (see the poll please), which do you think will provide the best performance and efficiency?

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Efficiency of moving sprites? (BitBlt and image controls)

    Don't use any controls.

    I have an "LoadPictureToDC" function (at home), which loads the image straight from disk, and into a device context. When I get home I'll show you it (around 7 hours time).

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3
    Hyperactive Member metalmidget's Avatar
    Join Date
    Mar 2007
    Location
    Melbourne, Australia
    Posts
    342

    Re: Efficiency of moving sprites? (BitBlt and image controls)

    I'm interested in that too, Chem. Is it 6 or .net?

  4. #4
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Efficiency of moving sprites? (BitBlt and image controls)

    You should load all your pictures into dc's and then use those dc's to build the final picture in another dc.

    And you don't need a dc for each object in the game.
    There may be a million bullets but you can use a single dc for the bullet picture.
    You then tell all these bullets to use that dc as their picture source.

  5. #5

    Thread Starter
    New Member Son of Makuta's Avatar
    Join Date
    Sep 2007
    Posts
    14

    Re: Efficiency of moving sprites? (BitBlt and image controls)

    Thanks all.

    I've found a LoadImgDC type function myself, on a tutorial. Methinks I'll use that. Saves on RAM.

    One small problem... well, quite sizeable really... I've made a BitBlt tester and it refuses to work. (It's just a black screen - picture box - and when you press enter an image is supposed to appear.) Everything's done right, y'know, no typos, the properties are good, etc. I checked it 3 gazillion times before I noticed something...

    It does work when I put in an error. If I comment out a Dim statement, when running, it throws me 'Variable not defined' as usual, then once I fix it, it returns to the program with the image appearing. If the program is left correct and run, it doesn't work. :\

    I've tried removing and reinstalling VB (6.0 Professional if anyone's curious) and it didn't cure the problem. D'you think it's my laptop, something weird with the program, or what? The examples I've got from tutorials work fine.

  6. #6
    Hyperactive Member singularis's Avatar
    Join Date
    Nov 2006
    Location
    Over There!
    Posts
    372

    Re: Efficiency of moving sprites? (BitBlt and image controls)

    Show us the code you are using and I will take a look at it.
    If what I said was helpful, give me rep!

    My Complete Games: -- 2D Zone (Space Shooter game) || _2D Zone 2_ || Ninja Blob (2D platformer) || Dren (Co-op up to 4 player base defence game)

    My Projects: -- The Dread Engine (2D VB game Engine) || A* Path Finding


    An excellent site for learning DirectX7, 8 & 9 (for VB6, C# & VB.net) would be: directx4vb.vbgamer.com --- For my projects and games see: pieper.freehostia.com

  7. #7
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Efficiency of moving sprites? (BitBlt and image controls)

    Oh I completely forgot about this last night.. sorry, I just continued with my homework :/

    Will post for metalmidget later tonight.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  8. #8
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Efficiency of moving sprites? (BitBlt and image controls)

    Ok, here:
    vb Code:
    1. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    2. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    3. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    4.  
    5. Function LoadPictureToDC(sFilename As String, hHandle As Long) As Long
    6. On Error Resume Next
    7. FileName = sFilename
    8. Dim LoadGraphicDCTEMP As Long
    9. LoadGraphicDCTEMP = CreateCompatibleDC(GetDC(hHandle))
    10. SelectObject LoadGraphicDCTEMP, LoadPicture(sFilename)
    11. LoadPictureToDC = LoadGraphicDCTEMP
    12. End Function
    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  9. #9

    Thread Starter
    New Member Son of Makuta's Avatar
    Join Date
    Sep 2007
    Posts
    14

    Re: Efficiency of moving sprites? (BitBlt and image controls)

    @singularis: Thanks. Here's the project in its entirety, see the zip file. There's a lot of commented-out lines of code that I'm switching between as I test the thing. I just tested it on another computer, and it behaved the same way as it does on my laptop.

    @chemicalNova: Yah, that's the one I've got, although with slightly different names.
    Attached Files Attached Files

  10. #10
    Hyperactive Member singularis's Avatar
    Join Date
    Nov 2006
    Location
    Over There!
    Posts
    372

    Re: Efficiency of moving sprites? (BitBlt and image controls)

    To simplfy things don't lay buffers on top of each other use seperate forms.
    If what I said was helpful, give me rep!

    My Complete Games: -- 2D Zone (Space Shooter game) || _2D Zone 2_ || Ninja Blob (2D platformer) || Dren (Co-op up to 4 player base defence game)

    My Projects: -- The Dread Engine (2D VB game Engine) || A* Path Finding


    An excellent site for learning DirectX7, 8 & 9 (for VB6, C# & VB.net) would be: directx4vb.vbgamer.com --- For my projects and games see: pieper.freehostia.com

  11. #11

    Thread Starter
    New Member Son of Makuta's Avatar
    Join Date
    Sep 2007
    Posts
    14

    Re: Efficiency of moving sprites? (BitBlt and image controls)

    Separate forms? Hmm. It still doesn't work with only using one picture box, or blitting to the form, or even using CreateCompatibleDC for a buffer that only exists in the computer's imagination. I'll try it anyway. Thanks.

  12. #12
    Hyperactive Member metalmidget's Avatar
    Join Date
    Mar 2007
    Location
    Melbourne, Australia
    Posts
    342

    Re: Efficiency of moving sprites? (BitBlt and image controls)

    cheers Chem that should let me neaten things up a little in my own project.
    metal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width