-
Senior Member
How do I do group sorts?
the array contains a bunch of objects, where pairs of objects have a same value for _myId.... Now I want to depth sort the objects in pairs, that is, sort them by their y and keep the objects with same id together. But the function I wrote doesn't seem to be working....any ideas?
Code:
private function depthSort():void
{
var tempArray:Array = gameObjects;
tempArray.sortOn(["_myId","y"], [Array.NUMERIC,Array.NUMERIC|Array.DESCENDING]);
var i:uint = tempArray.length;
while (i--)
{
trace(tempArray[i].y + " : " + tempArray[i]._myId+" -> "+i);
if (_world.getChildIndex(tempArray[i]) != i)
{
_world.setChildIndex(tempArray[i],i);
}
}
}
If you like me, add me to your friends list .
PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!
My Arcade My Blog
Add me on twitter:
-
M.D.
works for me:
Code:
var arr:Array = [];
for (var i:int = 0; i < 200; i++) {
arr.push({ id:int(Math.random() * 100), y:Math.random() * 800 });
}
arr.sortOn(["id", "y"], Array.NUMERIC);
var p:int = 0;
for (i = 0; i < arr.length; i++) {
if (arr[i].id != p) {
trace("");
}
trace(arr[i].id + " : " + arr[i].y);
p = arr[i].id;
}
paste that in flash and run it, you'll see groups of id's together sorted with lowest y to highest.
-
Senior Member
yeh, that is exactly what I am doing, but it's not working..... my objects are being grouped as per their id, but not sorted as per "y". 1 is is always at index 0, and 2 id is always at index 2....I dunno what I am doing wrong...
If you like me, add me to your friends list .
PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!
My Arcade My Blog
Add me on twitter:
-
M.D.
try this sorting option for now:
tempArray.sortOn(["_myId","y"], Array.NUMERIC);
-
Senior Member
Already tried it, that was the first thing i did
If you like me, add me to your friends list .
PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!
My Arcade My Blog
Add me on twitter:
-
M.D.
maybe post a sample fla then, you've got your "y" property as public? I've heard that using getters for sorting can be buggy.
-
Senior Member
Well I solved the problem for now, by filtering the array for keeping only one object of a group and then sorting it. I don't know how the filter will hit the performance on the long run though....oh well....Thanks for the help mr.malee
If you like me, add me to your friends list .
PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!
My Arcade My Blog
Add me on twitter:
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
|