Z-order

Hi,

If i understand well, SDL has no Z-order. As a consequence, a sprite is "below"
another one only if it is drawn before in the draw-function.

Am I right or is there a subtle way i didn’t see? I think it’s very strange to
not have such system

Yep, you’re absolutely right. SDL doesn’t offer z-ordering, so if you
need it you’ll have to implement it yourself.On 5.6.2009, at 23:20.28, Naroin wrote:

Hi,

If i understand well, SDL has no Z-order. As a consequence, a sprite
is "below"
another one only if it is drawn before in the draw-function.

Am I right or is there a subtle way i didn’t see? I think it’s very
strange to
not have such system


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Doing this is called “painter’s method,” BTW.

-bill!On Fri, Jun 05, 2009 at 11:25:52PM +0300, Markus Kauppila wrote:

Yep, you’re absolutely right. SDL doesn’t offer z-ordering, so if you
need it you’ll have to implement it yourself.

Markus Kauppila <markus.kauppila gmail.com> writes:

Yep, you’re absolutely right. SDL doesn’t offer z-ordering, so if you
need it you’ll have to implement it yourself.

ok, is there any document, or simply a smart idea of how to do that?

I’ve for now n arrays of sprites, each array representing a Z level. So if a
sprite needs to change its Z-level, i need to move it in memory. Not really
smart…

That’s really the best way to do it. Except use arrays of sprite
references, so you don’t need to move the sprite in memory,
just the pointer. That works much better.>----- Original Message ----

From: Naroin
Subject: Re: [SDL] Z-order

Markus Kauppila <markus.kauppila gmail.com> writes:

Yep, you’re absolutely right. SDL doesn’t offer z-ordering, so if you
need it you’ll have to implement it yourself.

ok, is there any document, or simply a smart idea of how to do that?

I’ve for now n arrays of sprites, each array representing a Z level. So if a
sprite needs to change its Z-level, i need to move it in memory. Not really
smart…

Well, you could store pointers in each zlevel instead of the actual sprites.

-JustinOn Fri, Jun 5, 2009 at 4:52 PM, Naroin wrote:

Markus Kauppila <markus.kauppila gmail.com> writes:

Yep, you’re absolutely right. SDL doesn’t offer z-ordering, so if you
need it you’ll have to implement it yourself.

ok, is there any document, or simply a smart idea of how to do that?

I’ve for now n arrays of sprites, each array representing a Z level. So if a
sprite needs to change its Z-level, i need to move it in memory. Not really
smart…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

You can try SDLayer, I’ve never used it, but i’m sure it will help, at
least with some ideas for you to implement in your code.
SDLayer implements the representation of layers, so you might put each
Z level in a different layer…

More:
http://code.google.com/p/sdl-layer/

2009/6/5 Naroin :> Markus Kauppila <markus.kauppila gmail.com> writes:

Yep, you’re absolutely right. SDL doesn’t offer z-ordering, so if you
need it you’ll have to implement it yourself.

ok, is there any document, or simply a smart idea of how to do that?

I’ve for now n arrays of sprites, each array representing a Z level. So if a
sprite needs to change its Z-level, i need to move it in memory. Not really
smart…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

If you’re using C++, then you could save trouble by using vectors or
lists. Then you could replace the sorting function with your own as
well, and there you have your z-based drawing order.

Jonny D

Or you could simply iterate an array multiple times, one for each
z-order level. Or sort the array by Z-order, then iterate it once.
(e.g., use “qsort()” or somesuch)

-bill!On Fri, Jun 05, 2009 at 01:55:13PM -0700, Mason Wheeler wrote:

That’s really the best way to do it. Except use arrays of sprite
references, so you don’t need to move the sprite in memory,
just the pointer. That works much better.

That works well if you have a pretty static sprite list. But if sprites
are frequently being created and deleted, and you have to keep
slipping them into the middle of your array, it can bog things
down.>----- Original Message ----

From: Bill Kendrick
Subject: Re: [SDL] Z-order

On Fri, Jun 05, 2009 at 01:55:13PM -0700, Mason Wheeler wrote:

That’s really the best way to do it. Except use arrays of sprite
references, so you don’t need to move the sprite in memory,
just the pointer. That works much better.

Or you could simply iterate an array multiple times, one for each
z-order level. Or sort the array by Z-order, then iterate it once.
(e.g., use “qsort()” or somesuch)

That works well if you have a pretty static sprite list. But if
sprites are frequently being created and deleted, and you have to keep
slipping them into the middle of your array, it can bog things
down.

How about using a Z array of which each element is a doubly-linked list
of sprites of that level? Thus, moving a sprite from one Z level to an
other is O(1), so is addition and deletion while dumping all the sprites
to the screen is O(N). Assuming, of course, that you have a finite (and
not very large) number of distinct Z values.

An unrelated issue: I’ve noticed that Sam was on the Loki team. Any
idea what happened to the Myth-II Linux port source ?

Zoltan

Well, if you have one array (or linked list, or whatever) for each Z level,
you wouldn’t be cramming things in-between, you’d just be adding things
to a particular list.

Some form of binary tree may be even better. Ah, Data Structures class.
How little I get to use you in my day job. :frowning: (Sorry Dr. Gordon!)

-bill!On Fri, Jun 05, 2009 at 02:46:43PM -0700, Mason Wheeler wrote:

That works well if you have a pretty static sprite list. But if sprites
are frequently being created and deleted, and you have to keep
slipping them into the middle of your array, it can bog things
down.

That works well if you have a pretty static sprite list. But if sprites
are frequently being created and deleted, and you have to keep
slipping them into the middle of your array, it can bog things
down.

Well, if you have one array (or linked list, or whatever) for each Z level,
you wouldn’t be cramming things in-between, you’d just be adding things
to a particular list.

Yep. That’s why I said that was the best solution.>----- Original Message ----

From: Bill Kendrick
Subject: Re: [SDL] Z-order
On Fri, Jun 05, 2009 at 02:46:43PM -0700, Mason Wheeler wrote:

That works well if you have a pretty static sprite list. ?But if sprites
are frequently being created and deleted, and you have to keep
slipping them into the middle of your array, it can bog things
down.

In that case you can just use a priority queue to store them. Good old
heap sort saves the day once again.

Bob PendletonOn Fri, Jun 5, 2009 at 4:46 PM, Mason Wheeler wrote:

----- Original Message ----
From: Bill Kendrick
Subject: Re: [SDL] Z-order

On Fri, Jun 05, 2009 at 01:55:13PM -0700, Mason Wheeler wrote:

That’s really the best way to do it. ?Except use arrays of sprite
references, so you don’t need to move the sprite in memory,
just the pointer. ?That works much better.

Or you could simply iterate an array multiple times, one for each
z-order level. ?Or sort the array by Z-order, then iterate it once.
(e.g., use “qsort()” or somesuch)


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


±----------------------------------------------------------

I feel like no one has suggested a rather obvious alternative
approach: use OpenGL with your SDL application.

There are a lot of reasons this may or may not be appropriate. Have fun!On Fri, Jun 5, 2009 at 4:20 PM, Naroin wrote:

Hi,

If i understand well, SDL has no Z-order. As a consequence, a sprite is "below"
another one only if it is drawn before in the draw-function.

Am I right or is there a subtle way i didn’t see? I think it’s very strange to
not have such system


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


http://codebad.com/