add y sort option

This commit is contained in:
John Alanbrook 2024-08-22 14:43:04 -05:00
parent b31069fe91
commit b589a742cf

View file

@ -528,9 +528,11 @@ render.init = function() {
render.sprites = function render_sprites(gridsize = 1) render.sprites = function render_sprites(gridsize = 1)
{ {
// When y sorting, draw layer is firstly important followed by the gameobject position // When y sorting, draw layer is firstly important followed by the gameobject position
var buckets;
if (render.y_sort) {
profile.frame("y bucketing"); profile.frame("y bucketing");
var sps = Object.values(allsprites); var sps = Object.values(allsprites);
var buckets = {}; buckets = {};
for (var sprite of sps) { for (var sprite of sps) {
var layer = (sprite.gameobject.drawlayer*10000)-sprite.gameobject.pos.y; var layer = (sprite.gameobject.drawlayer*10000)-sprite.gameobject.pos.y;
@ -551,6 +553,18 @@ render.sprites = function render_sprites(gridsize = 1)
return 1; return 1;
}); });
profile.endframe(); profile.endframe();
} else {
profile.frame("sorting");
var sprite_buckets = component.sprite_buckets();
var buckets = Object.entries(sprite_buckets).sort((a,b) => {
var na = Number(a[0]);
var nb = Number(b[0]);
if (na < nb) return -1;
return 1;
});
profile.endframe();
}
/* /*
profile.frame("bucketing"); profile.frame("bucketing");
var sps = Object.values(allsprites); var sps = Object.values(allsprites);
@ -568,18 +582,6 @@ render.sprites = function render_sprites(gridsize = 1)
} }
profile.endframe(); profile.endframe();
profile.frame("sorting");
var sprite_buckets = component.sprite_buckets();
var buckets = Object.entries(sprite_buckets).sort((a,b) => {
var na = Number(a[0]);
var nb = Number(b[0]);
if (na < nb) return -1;
return 1;
});
profile.endframe();
*/ */
profile.frame("drawing"); profile.frame("drawing");