0

Now I could be wrong about this but after testing it all day, I have discovered...

When adding a widget and setting the z-index, the value "0" seems to be the magic depth.

If a widget's Z is at 0, it will be drawn on top of everything that's not at 0, Z wise.

It doesn't matter if a widget has a z-index of 99, -999, 10, -2 or what ever... It will not appear on top of a widget who's z-index is set to 0.

It gets more strange though...

Any index less than -2 or greater than 2 seems to create an "index out of range" error. Funny thing is...when I was working with a background and sprite widget, the background's Z was set to 999 and no errors. When I added another sprite widget, that's when the -2 to 2 z-index limitation appeared.

Yeah I know...sounds whacked!

My question is, am I right about "0" being the magic Z value?

If so, creating a simple 23D effect like making a sprite move being a big rock will take some unwanted code.

Since you can only set Z when adding,a widget, one must remove and immediately add back, with the new Z value...a widget.

You'll have to do this with the moving sprite and the overlapping object in question. Hell, I already have that code practically written but I want to find out from Kivy pros, is there a way to set z-index without removing and adding a widget.

If not, I'll have to settle for the painful way.

My version of Kivy is 1.9.0

Cotownsend78
  • 101
  • 1
  • 7

2 Answers2

1

What do you mean by z-order? Drawing order is determined entirely by order of widgets being added to the parent, and the index argument to add_widget is just a list index at which the widget will be inserted. The correct way to change drawing order amongs widgets is to remove and add them (actually you can mess with the canvases manually but this is the same thing just lower level, and not a better idea).

inclement
  • 29,124
  • 4
  • 48
  • 60
  • Looking at it your way, if a screen had 50 widgets and 49 of them needed a depth reordering, all 49 widgets would have to be removed and added back, but in the new order... That would be rough. Given Kivy is just a set of APIs, it's hard to be disappointed. I can probably accomplish what I want by manipulating 2 widgets at a time, when needed. – Cotownsend78 Jul 09 '15 at 11:10
  • I suppose reordering problems don't come up much, it's not an unreasonable thing to want to do though. You could manage it yourself by inventing an ordering property then adding/removing them all at once with an argsort-type function like at http://stackoverflow.com/questions/3382352/equivalent-of-numpy-argsort-in-basic-python – inclement Jul 09 '15 at 11:16
-1

I found a working solution using basic logic based on the fact widgets have to be removed and added again in order to control depth/draw order.

I knew the Main Character widget had to be removed along with the object in question...so I created a Main Character Parent widget, which defines and control the Main Character, apart from its Graphic widget.

My test involves the Main Character walking in front of a large rock, then behind it...creating a 23D effect.

I simply used the "y-" theory along with widget attach and detach code to create the desired effect.

The only thing that caught me off guard was the fact my Graphic widget for my Actor was loading textures. That was a big no no because the fps died.

Simple fix, moved the texture loading to the Main Character Parent widget and the loading is done once for all-time.

PS, if anyone knows how to hide the scrollbars and wish to share that knowledge, it'll be much appreciated. I haven't looked for an API solution for it yet but I will soon.

Right now I'm just trying to make sure I can do the basic operations necessary for creating a commercial 23D game (handhelds).

I'm a graphic artist and web developer so coming up with lovely visuals won't be an issue. I'm more concerned with what'll be "under the hood" so to say. Hopefully enough, lol.

Cotownsend78
  • 101
  • 1
  • 7