|
-
Sep 27th, 2002, 09:58 AM
#1
Thread Starter
Fanatic Member
ZOrder - Own Engine
Hi, Guys.
Does anyone have a specified way of doing the ZOrder with BitBlt, with several objects?
Thank you,
Arie.
-
Sep 27th, 2002, 09:18 PM
#2
Fanatic Member
Put them in an array arranging them by zorder, then blit the array or something
-
Sep 28th, 2002, 10:04 AM
#3
Thread Starter
Fanatic Member
I thought about it but I don't know how to use it.
Does anyone has a ready code for this?
Please help.
Thank you,
Arie.
-
Sep 28th, 2002, 10:12 AM
#4
Good Ol' Platypus
Just blit them in order from back to front, use an array like that if you want!
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Sep 28th, 2002, 10:15 AM
#5
Thread Starter
Fanatic Member
My objects are not on an array, not like Object(1 to 10).
I have the objects in different names. How do I get all ordered?
Thank you,
Arie.
-
Sep 28th, 2002, 12:40 PM
#6
PowerPoster
-
Sep 28th, 2002, 03:54 PM
#7
Thread Starter
Fanatic Member
Ok. Got it. My objects are now in an array with no specific bound.
Now how do I arrange the array in the ZOrder?
Thank you so far,
Arie.
-
Sep 28th, 2002, 06:59 PM
#8
Fanatic Member
Argggg, just add a zindex to your UDT and use this function
VB Code:
[edit]
function missing
[/edit]
I wrote alot of code and im not sure that it works, ill post again later when i have more time to finish the quicksort function.
Basically what you do is use some kind of a sorting algorythm, search google (vb sort function), and use that to sort your data. The easiest to implement is bubble sort, start from the begining and check every 2 objects and compare, untill entire array is sorted, there is more to this. Search google. I will post a complete function later.
-
Sep 28th, 2002, 07:52 PM
#9
Fanatic Member
Alright, im done.
Here is the code, it took me a while to do it but im finally done. Hey Arie, Next time do a search here and if you cant come up with anything, do a search on google, and planet source code. It will give you all the code you want.
VB Code:
' The type UDT needs to have a variable called ZIndex
' you can call it anything but you have to be sure to do
' a string replace of TheType to whatever you called yours
' - if you are having ptoblems with it, just reply
Type TheType
ZIndex As Long
' all other stuff goes here
End Type
' swap objects
Private Sub SwapObj(ByRef i1 As TheType, ByRef i2 As TheType)
Static i0 As TheType
i0 = i1
i1 = i2
i2 = i0
End Sub
' This is the function that you call, it will sort your array as you like
Function ReArrange (ByRef TheArray() As TheType, Optional ByVal Asc As Boolean = True)
Dim iLBound As Integer
Dim iUBound As Integer
iLBound = LBound(TheArray)
iUBound = UBound(TheArray)
' Quick sort first,
' this is a highly rapid and recursive sort algorythm
' *note* dont change the 4 here (i dont know why)
' here is the original quote:
' [quote]
' *NOTE* the value 4 is VERY important here !!!
' DO NOT CHANGE 4 FOR A LOWER VALUE !!!
' [/quote]
QuickSort TheArray, 4, iLBound, iUBound
' Insertion Sort next
' This will finish up on the bounds
Dim iTemp As TheType
Dim i As Integer
Dim j As Integer
For i = iLBound + 1 To iUBound
iTemp = TheArray(i)
j = i
Do While j > iLBound
If TheArray(j - 1).ZIndex <= iTemp.ZIndex Then Exit Do
TheArray(j) = TheArray(j - 1)
j = j - 1
Loop
TheArray(j) = iTemp
Next i
' Now take care of the order
If Not Asc Then
' Reverse the array
While iLBound < iUBound
SwapObj TheArray(iLBound), TheArray(iUBound)
iLBound = iLBound + 1
iUBound = iUBound - 1
Wend
End If
End Function
' Function Adapted from a modified version of TriQuickSort,
' by Philippe Lord, posted on PSC on 6/29/2001 2:36:08 AM
' All Props due to their rightful owners, I just put the
' ideas together :)
Function QuickSort (ByRef iArray() As TheType, ByVal iSplit As Long, _
ByVal iMin As Long, ByVal iMax As Long)
If (iMax - iMin) > iSplit Then
i = (iMax + iMin) / 2
If iArray(iMin).ZIndex > iArray(i).ZIndex Then SwapObj iArray(iMin), iArray(i)
If iArray(iMin).ZIndex > iArray(iMax).ZIndex Then SwapObj iArray(iMin), iArray(iMax)
If iArray(i).ZIndex> iArray(iMax).ZIndex Then SwapObj iArray(i), iArray(iMax)
j = iMax - 1
SwapObj iArray(i), iArray(j)
i = iMin
iTemp = iArray(j).ZIndex
Do
Do
i = i + 1
Loop While iArray(i).ZIndex < iTemp
Do
j = j - 1
Loop While iArray(j).ZIndex > iTemp
If j < i Then Exit Do
SwapObj iArray(i), iArray(j)
Loop
SwapObj iArray(i), iArray(iMax - 1)
QuickSort iArray, iSplit, iMin, j
QuickSort iArray, iSplit, i + 1, iMax
End If
End Function
I havent tested this code but it should work if not, reply and we'll help ya
-
Sep 29th, 2002, 02:24 PM
#10
Thread Starter
Fanatic Member
Oh Man! I will try it out...
I hope it works...
Thank you, MoMad!
I'll reply when done checking.
Thank you all,
Arie.
-
Sep 30th, 2002, 05:54 AM
#11
Thread Starter
Fanatic Member
It works!! Thanks man...
One only thing is wrong here: You create the TheType too much,
to make the array, you should put only the index of every TheType.
Thank you,
Arie.
-
Sep 30th, 2002, 11:40 AM
#12
Fanatic Member
No, just do a string replace "TheType" to whatever you call your UDT. It HAS to be a UDT and just switching the zindexes wont work, you have to switch the entire udt.
-
Sep 30th, 2002, 01:14 PM
#13
Thread Starter
Fanatic Member
Ok...
Now, does this code arrange the objects well?
VB Code:
Dim K as Integer, L as Integer, iMax as Integer
For K = 1 To UBound(ObjOrder) - 1
iMax = K
For L = (K + 1) To UBound(ObjOrder)
If Object(L).oPosition.pY < _
Object(iMax).oPosition.pY Then iMax = L
Next L
'Swapping
Temp = ObjOrder(K)
ObjOrder(K) = ObjOrder(iMax)
ObjOrder(iMax) = Temp
Next K
Thank you,
Arie.
-
Sep 30th, 2002, 02:22 PM
#14
Fanatic Member
No and infact i have no idea what the purpose of this is!! Your variables dont match the things they do... you have ObjOrder but then you are using Object instead? You have iMax but then you are assigning it the min value? You are swapping K and iMax but why?
Wait a minute, i remember this algorythm, insertion sort right? Well kindof.. anyways, it kind of makes sense and it kindo doesnt...
...
1 min and copy/paste into vb and testing later....
...
it works!! One problem though?? What is up with Object(k).oPosition?? Isnt it supposed to be ObjOrder(k).oPosition??
-
Oct 1st, 2002, 11:06 AM
#15
Thread Starter
Fanatic Member
You See, iMax is ment to be iMin, and my objects are in the Object array that have all the properties of an object,
and the ObjOrder array is an array of integer, that says the order of the objects by their number.
I hope you understand it a little bit better now, exuse me for not explaining. Can you help me? it does not order my objects correctly...
Please Help!
Thank you,
Arie.
-
Oct 1st, 2002, 01:01 PM
#16
Fanatic Member
I see, your problem here is that your array gets ordered correctly but that ordering has no effect whatsoever on your actual object array. Add a field called "ZIndex" to your object array and then order the objects according to the ZIndex...
Actually try this: (you dont need objorder)
VB Code:
Dim K as Integer, L as Integer, iMin as Object
Dim Temp As Object
Dim size As Integer
size = UBound(Object)
For K = LBound(Object) To size - 1
iMin = Object(K)
For L = (K + 1) To size
If Object(L).oPosition.pY < _
iMin.oPosition.pY Then iMin = Object(L)
Next L
'Swapping (the objects)
Temp = Object(K)
Object(K) = iMin
iMin = Temp
Next K
-
Oct 2nd, 2002, 04:56 AM
#17
Thread Starter
Fanatic Member
Thank you very much but I found the solution!
Here's the corrected code:
VB Code:
Dim K As Integer, L As Integer, iMax As Integer, Temp As Integer
ReDim Preserve ObjOrder(1 To UBound(Object))
For K = 1 To UBound(ObjOrder)
ObjOrder(K) = K
Next K
For K = 1 To UBound(ObjOrder) - 1
iMax = K
For L = (K + 1) To UBound(ObjOrder)
If Object(ObjOrder(L)).oPosition.pY < _
Object(ObjOrder(iMax)).oPosition.pY Then iMax = L
Next L
Temp = ObjOrder(K)
ObjOrder(K) = ObjOrder(iMax)
ObjOrder(iMax) = Temp
Next K
Thank you anyway,
Arie.
-
Oct 2nd, 2002, 03:22 PM
#18
Fanatic Member
I dont understand, what are you trying to rearrange? The surfaces/objects or the arbitary numbers in objorder array?
-
Oct 3rd, 2002, 10:11 AM
#19
Thread Starter
Fanatic Member
My game isn't 2d from up view, it's a 2d game the objects can hide behind the other objects, including players.
Later on, I'll upload my completed game, "Magical Operation".
I hope I won't have any other problems.
Thank you all for helping,
Arie.
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
|