auts: depth-sort sprites in spritesys
This commit is contained in:
parent
c2cd0716d1
commit
25a5d5f5a2
|
@ -4,6 +4,24 @@ interface Drawable {
|
|||
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 {
|
||||
mut:
|
||||
sys &System // Embed
|
||||
|
@ -32,6 +50,26 @@ fn (mut s SpriteSys) draw() {
|
|||
|
||||
// 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 {
|
||||
//el.draw()
|
||||
//x := Drawable{el}
|
||||
|
@ -39,7 +77,10 @@ fn (mut s SpriteSys) draw() {
|
|||
//mut x := &Drawable(el)
|
||||
mut x := &Sprite(el)
|
||||
x.draw()
|
||||
|
||||
println(x.y)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
fn (mut s SpriteSys) update(dt f32) {
|
||||
|
|
Loading…
Reference in New Issue