|
-
Dec 24th, 2006, 02:01 PM
#1
Thread Starter
Member
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?
-
Dec 24th, 2006, 02:10 PM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Dec 24th, 2006, 02:13 PM
#3
Thread Starter
Member
Re: Collision and Zorder with bitblt
Ok, thnx. :P
I just hope someone knows the answer.
I don't think it easy to solve.
-
Dec 24th, 2006, 02:23 PM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Dec 24th, 2006, 03:29 PM
#5
Thread Starter
Member
Re: Collision and Zorder with bitblt
Er...
Have you just removed my topic about the sprites?
I can't find it anymore...
-
Dec 24th, 2006, 04:03 PM
#6
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.
-
Dec 24th, 2006, 04:17 PM
#7
Thread Starter
Member
Re: Collision and Zorder with bitblt
Sounds complicated and a lot of work...
:P
-
Dec 24th, 2006, 08:37 PM
#8
Frenzied Member
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.
-
Dec 27th, 2006, 05:46 AM
#9
Thread Starter
Member
Re: Collision and Zorder with bitblt
I can't do it.
Can somebody please give me an example code?
-
Dec 28th, 2006, 01:56 AM
#10
Frenzied Member
Re: Collision and Zorder with bitblt
VB Code:
Type tObject
X As Long
Y As Long
Img As clsHdc
End Type
Dim Objects() As tObject
Dim tmp As tObj
Dim i as Long
Dim j as Long
'sort
For i = UBound(Objects) - 1 To 1 Step -1
For j = 0 to i - 1
IF Array(j).Y > Array(j + 1).Y Then
Temp = Array(j)
Array(j) = Array(j + 1)
Array(j + 1) = tmp
End If
Next j
Next i
'draw
For i = 0 To UBound(Objects)
BitBlt PicBox.Hdc, Objects(i).X, Objects(i).Y - Objects(i).Img.Height, _
Objects(i).Img.Width, Objects(i).Img.Height, _
Objects(i).Img.Hdc, 0, 0, _
vbSrcCopy
Next i
-
Dec 28th, 2006, 04:28 AM
#11
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.
-
Dec 28th, 2006, 05:11 AM
#12
Frenzied Member
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.
-
Dec 28th, 2006, 07:34 AM
#13
Thread Starter
Member
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...
-
Dec 28th, 2006, 08:28 AM
#14
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
-
Dec 28th, 2006, 11:00 AM
#15
Thread Starter
Member
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...
 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.
 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.
-
Dec 28th, 2006, 12:52 PM
#16
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.
-
Dec 28th, 2006, 01:05 PM
#17
Thread Starter
Member
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...
-
Dec 28th, 2006, 01:22 PM
#18
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.
-
Dec 28th, 2006, 01:37 PM
#19
Thread Starter
Member
Re: Collision and Zorder with bitblt
 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...
-
Dec 28th, 2006, 01:56 PM
#20
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.
-
Dec 28th, 2006, 02:18 PM
#21
Thread Starter
Member
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...
-
Dec 28th, 2006, 11:22 PM
#22
Frenzied Member
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.
-
Dec 29th, 2006, 07:13 AM
#23
Thread Starter
Member
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.
-
Dec 29th, 2006, 10:00 AM
#24
Frenzied Member
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.
-
Dec 29th, 2006, 04:52 PM
#25
Thread Starter
Member
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...
-
Dec 30th, 2006, 11:01 AM
#26
Thread Starter
Member
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
-
Jan 1st, 2007, 09:37 PM
#27
Hyperactive Member
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.
-
Jan 8th, 2007, 02:40 AM
#28
Hyperactive Member
Re: Collision and Zorder with bitblt
Surely if you transblt there is no need for masks...
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
|