Results 1 to 28 of 28

Thread: Collision and Zorder with bitblt

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    58

    Collision and Zorder with bitblt

    I'm sorry I posted this topic twice but I really want help.
    I'm trying to make a rpg, but I can't get the zorder right.

    I want to get this effect:


    I know how to do the collision-thing but maybe I gotta change that to combine it with the Zorder-thing.
    Can someone please give me an example-code for an rpg-engine that can do this?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Collision and Zorder with bitblt

    Please dont post multiple threads as its not allowed.

    I moved your thread to the Games and Graphics Programming forum where it is most fitting and you will get better traffic for this type of thread.


    Ps, Welcome to the Forums.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    58

    Re: Collision and Zorder with bitblt

    Ok, thnx. :P
    I just hope someone knows the answer.
    I don't think it easy to solve.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Collision and Zorder with bitblt

    I'm not into game programming but this is the best place for this type of question. We have allot of good game programmers on our site but this being the holiday weekend it may be slow.

    Merry Christmas Eve!
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    58

    Re: Collision and Zorder with bitblt

    Er...
    Have you just removed my topic about the sprites?
    I can't find it anymore...

  6. #6
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Collision and Zorder with bitblt

    For each object you can have a mask. Then by checking the Y value you see if the sprite is behind the object or not. If it is behind, apply the mask to the sprite's mask to remove the visibility of the sprite for the non-visible areas.

    Needs some extra buffers, but should work nicely.

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    58

    Re: Collision and Zorder with bitblt

    Sounds complicated and a lot of work...
    :P

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

    Re: Collision and Zorder with bitblt

    Sort the objects by their Y-coordinates (of their feet/base!) and then bitblt them one by one, farthest first.

  9. #9

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    58

    Re: Collision and Zorder with bitblt

    I can't do it.
    Can somebody please give me an example code?

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

    Re: Collision and Zorder with bitblt

    VB Code:
    1. Type tObject
    2.     X As Long
    3.     Y As Long
    4.     Img As clsHdc
    5. End Type
    6.  
    7. Dim Objects() As tObject
    8. Dim tmp As tObj
    9. Dim i as Long
    10. Dim j as Long
    11.  
    12.     'sort
    13.     For i = UBound(Objects) - 1 To 1 Step -1
    14.         For j = 0 to i - 1
    15.             IF Array(j).Y > Array(j + 1).Y Then
    16.                 Temp         = Array(j)
    17.                 Array(j)     = Array(j + 1)
    18.                 Array(j + 1) = tmp
    19.             End If
    20.         Next j
    21.     Next i
    22.  
    23.     'draw
    24.     For i = 0 To UBound(Objects)
    25.         BitBlt PicBox.Hdc, Objects(i).X, Objects(i).Y - Objects(i).Img.Height, _
    26.                Objects(i).Img.Width, Objects(i).Img.Height, _
    27.                Objects(i).Img.Hdc, 0, 0, _
    28.                vbSrcCopy
    29.     Next i

  11. #11
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Collision and Zorder with bitblt

    But you're only taking sprites into account there, not walls etc. which often aren't in the same array with the sprites; and they're often solid tiles, although you might want to see through some of them.

    There could be improvement also for taking height into account in case the sprite can climb up.

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

    Re: Collision and Zorder with bitblt

    If things are in different arrays then you can make a function to combine several arrays into one before you sort it.

  13. #13

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    58

    Re: Collision and Zorder with bitblt

    Until now I've just bitblt everthing in 1 picture, no arrays, no layers. That goes fine. But I think, as soon as I'm gonna bitblt every layer seperatly, every sprite seperatly and every tile seperatly it's gonna be slow...

    And I think there's another problem. All the tiles have a standard-position (a number that can be divided by 32) but the sprite-positions vary. :P I'm not sure but I think that's gonna be a problem...

  14. #14
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Collision and Zorder with bitblt

    That is why I recommended masking: you can still use one picture for actual frame like you do now, but you'd also have mask layers from which you can get information on how much of a sprite you have to draw in case it is behind something. The number of these layers depends on how many tiles you have vertically. The trick is to draw the least possible for maximum speed. Basically the only thing that would change is that you'd store mask information of tiles in to (non-visible) buffers and before drawing sprites you'd make a mask buffer into which you first draw the sprite's mask and then remove the part that shouldn't be seen. Then draw this mask into final frame and draw the sprite. All of this is just BitBlt.

    Now you have (I guess):
    Predrawn background without sprites -> make a (to be) visible copy of it -> draw sprite mask -> draw sprite

    What you would have (I suggest):
    Predrawn background without sprites -> make a (to be) visible copy of it -> create a copy of sprite's mask -> apply tile mask removing visibility of a sprite's mask -> draw sprite

  15. #15

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    58

    Re: Collision and Zorder with bitblt

    Now my map has only 1 real layer. I'm just beginning with my game, I want to have 3 layers eventually. Background, layer where the sprite can bump into stuff and the foreground.
    But now I'm building the map in 2 stages. The completely colored tiles first and then the partly black tiles with transparentblt. And I set that map in a hdc-class and that's my 1 layer...

    Quote Originally Posted by Merri
    Now you have (I guess):
    Predrawn background without sprites -> make a (to be) visible copy of it -> draw sprite mask -> draw sprite
    I don't have a sprite mask, I do that with transparentblt.

    Quote Originally Posted by Merri
    That is why I recommended masking
    I was planning using masks.


    But I know what you mean and I'll try...

    [edit]Wait, then I still have to sort everything en bitblt everything seperately, right? Only then with the masks...
    Last edited by Compact3; Dec 28th, 2006 at 11:09 AM.

  16. #16
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Collision and Zorder with bitblt

    You only need to sort the sprites. Easiest way to sort is to make an indexes array of the visible sprites and then sort these based on the Y value. Then use index to point to the correct sprite when processing drawing and masks.


    (Index array = a regular Long array where you store only the index number of the sprite. This requires far less processing power than creating sprite object array and sorting that. And is also easier imo.)
    Last edited by Merri; Dec 28th, 2006 at 01:00 PM.

  17. #17

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    58

    Re: Collision and Zorder with bitblt

    I don't get it.
    I thought I should sort evertything by Y and then bitblt everything in that order and then I could see if a sprite (partly) disapears behind a tile. I don't get how I can see that with your system...

  18. #18
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Collision and Zorder with bitblt

    Because you know a sprite is behind a tile by it's Y value, you don't need to sort the tile masks. The sprites must be in correct order to prevent things as further sprite being printed on top of another that is closer. You can have tile masks for each tile row in a mask buffer, so if you have vertically 32 tiles, then you'd have 32 mask buffers for tiles (or two more, if you support full screen scrolling).

    Yup... pretty complex stuff and I hope I haven't written garbage. I've often thought about how this can be done, but I haven't written my own RPG engine; don't have the time to code games.

  19. #19

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    58

    Re: Collision and Zorder with bitblt

    Quote Originally Posted by Merri
    Because you know a sprite is behind a tile by it's Y value
    But some objects just fill half the tile...

  20. #20
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Collision and Zorder with bitblt

    I don't see a problem, except if you have objects that can be picked up or moved, in which case you'd handle the objects also via the same method you handle sprites.

  21. #21

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    58

    Re: Collision and Zorder with bitblt

    Well, if you know the Y-coördinates of the tiles and the sprites you still don't know where the solid parts of the tiles and the sprites begins. Because they're partly transparent en have an irregular form, so you don't know exactly what part of the sprite should be invisible just bij their Y-coördinates...

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

    Re: Collision and Zorder with bitblt

    If sprites are partly transparant then you can either work with masks or the transparantblt api.

    Just blit the mask in the same place as the sprite.
    Transparantblt requires no extra work.
    Last edited by jeroen79; Dec 28th, 2006 at 11:48 PM.

  23. #23

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    58

    Re: Collision and Zorder with bitblt

    Well, I'm using the transparentblt now to transblt them to the map. But that's not helping me deciding what part of the sprite should be invisible if it's behind an object and how to do that.

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

    Re: Collision and Zorder with bitblt

    You don't need to decide that.

    All you need to to is blit the objects in the right order. (farthest first, closest last)
    That is why you sort the objects before you start blitting.

    If a sprite is blitted over another then it will cover that other sprite.
    Transparantblt will make sure that parts set to be transparant are not drawn over the destination.

  25. #25

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    58

    Re: Collision and Zorder with bitblt

    Hmm...
    I'll have to change the way I'm building my map and stuff, but I think I can do it...

  26. #26

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    58

    Re: Collision and Zorder with bitblt

    Sorry, but now I have another very stupid problem..
    I still wanna work with masks for information about tiles and stuff, but here's the problem:
    I have like 1500 tiles to make masks out of!!!! :O
    Any suggestions? :P

  27. #27
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    Re: Collision and Zorder with bitblt

    I think theres an application that automaticly makes masks for images, though i remember it not being the greatest, maybe someone remembers the name or a link.

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

    Re: Collision and Zorder with bitblt

    Surely if you transblt there is no need for masks...
    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

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