Results 1 to 6 of 6

Thread: Guess the hDC

  1. #1

    Thread Starter
    Addicted Member NOMADMAN's Avatar
    Join Date
    Aug 2002
    Location
    Closer than you think
    Posts
    237

    Guess the hDC

    I'm making a psuedo game engine with bitblt. I'm storing the source hdc and destination hdc in a type (SPRIT) as longs. The source doesn't change but the destination (the bufferer picture) does change its hdc (i think when I cls it). How can I either store the picBUFFER.hDC or do I have to change the long in the sprite type everytime picBUFFER.hDC changes?

    Thanks!

    NOMAD

    ps: if its not possible I will just blit a background each time and not cls it... thanks y'all!

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Um.. cls is slow and bad but if you really want to use it - i recommend just to re-get the DC after clearing.. or since you're only flipping once a frame you can get it there each time.. that won't slow down anything.

  3. #3
    Lively Member
    Join Date
    Mar 2002
    Posts
    110
    don't cls it. my sprite engine uses a backbuffer whose hdc never changes and i'm blitting all over it. i just save the area under any moving sprites, so when they move, just the area that got changed needs to be redrawn, here is the pseudo code:

    save the tile under the first destination
    draw the sprite
    draw the saved tile
    move the sprite
    save the tile under the next location
    draw the sprite

    use classes, makes life easier

  4. #4
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    This technique is incredible slow if you're using a full-screen game where everything can be animated or moves out of the screen. This means for any jump'n'run, shoot'em'up, even top-down RPGs and everything. Since you have to redraw the whole environment in each frame (because the screen moved or it's just animated) there's no reason to use this backup technique.. However you don't need clearing with any of these methods, in fact as long as your game runs fullscreen (or full-buffer) you don't need clearing.

    And as golgo said, if you need a static background and just some moving sprites you can still backup and overdraw the moving parts.. Or just use DX for whatever you wanna do

  5. #5

    Thread Starter
    Addicted Member NOMADMAN's Avatar
    Join Date
    Aug 2002
    Location
    Closer than you think
    Posts
    237
    thanks guys, DX is my next project

    NOMAD

  6. #6
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421
    Just draw the background terrain once to a backbuffer stored in memory, since the terrain never changes. If you wanted the terrain to change or be animated, just animate a sprite that blends in with it, not the entire terrain again.

    I'm suggesting using layers. Layer(0) would be the terrain (grass, desert, etc.) and would be drawn first to a backbuffer in memory, and when you need to scroll or whatever, just blit it from the backbuffer starting at the X and Y offsets, and the width and height of the display area. Although this may be a bad idea if you have huge maps, it's a good direction to take if your maps are fairly small.

    Back to layers... you would draw Layer(0) once, and then loop through Layer(1) (maybe buildings?) to Layer(2) (sprites?) and then Layer(3) (items/doors?), starting from the top of the screen to the bottom left to right. Your code may look like this:

    VB Code:
    1. Blit Layer(0)
    2.  
    3. Do
    4.     For i = 1 to LayerCount - 1
    5.         Blit Layer(i)
    6.     Next i
    7.    
    8.     DoEvents
    9. Loop
    Anymore questions, just ask.
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

Posting Permissions

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



Click Here to Expand Forum to Full Width