auts: depth-sort sprites in spritesys
This commit is contained in:
parent
c2cd0716d1
commit
25a5d5f5a2
|
@ -4,6 +4,24 @@ interface Drawable {
|
||||||
draw()
|
draw()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn depth_compare(a, b &Sprite) int {
|
||||||
|
|
||||||
|
//println(a.y)
|
||||||
|
//println(b.y)
|
||||||
|
|
||||||
|
if a.y < b.y {
|
||||||
|
//println("ret -1")
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if a.y > b.y {
|
||||||
|
//println("ret 1")
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
//println("ret 0")
|
||||||
|
//pp(4)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
struct SpriteSys {
|
struct SpriteSys {
|
||||||
mut:
|
mut:
|
||||||
sys &System // Embed
|
sys &System // Embed
|
||||||
|
@ -32,6 +50,26 @@ fn (mut s SpriteSys) draw() {
|
||||||
|
|
||||||
// XXX TODO sort sprites by z
|
// XXX TODO sort sprites by z
|
||||||
|
|
||||||
|
//mut sorted_elems := s.sys.elems.clone()
|
||||||
|
//sorted_elems.sort_with_compare(depth_compare)
|
||||||
|
|
||||||
|
mut sorted_sprites := []Sprite{}
|
||||||
|
for el in s.sys.elems {
|
||||||
|
mut x := &Sprite(el)
|
||||||
|
sorted_sprites << x
|
||||||
|
}
|
||||||
|
|
||||||
|
sorted_sprites.sort_with_compare(depth_compare)
|
||||||
|
|
||||||
|
for x in sorted_sprites {
|
||||||
|
mut z := x
|
||||||
|
z.draw()
|
||||||
|
//println(z.y)
|
||||||
|
}
|
||||||
|
|
||||||
|
//pp(3)
|
||||||
|
|
||||||
|
/*
|
||||||
for el in s.sys.elems {
|
for el in s.sys.elems {
|
||||||
//el.draw()
|
//el.draw()
|
||||||
//x := Drawable{el}
|
//x := Drawable{el}
|
||||||
|
@ -39,7 +77,10 @@ fn (mut s SpriteSys) draw() {
|
||||||
//mut x := &Drawable(el)
|
//mut x := &Drawable(el)
|
||||||
mut x := &Sprite(el)
|
mut x := &Sprite(el)
|
||||||
x.draw()
|
x.draw()
|
||||||
|
|
||||||
|
println(x.y)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut s SpriteSys) update(dt f32) {
|
fn (mut s SpriteSys) update(dt f32) {
|
||||||
|
|
Loading…
Reference in a new issue