setZOrder not working?

72 views
Skip to first unread message

Arne Brutschy

unread,
Jan 19, 2013, 2:03:45 PM1/19/13
to caa...@googlegroups.com
Hello,

from the documentation I expect this code:

scene.addChild(circleActor);
scene.setZOrder(circleActor, Number.MAX_VALUE);
scene.addChild(squareActor);

causes the circleActor always be on top of the squareActor. This does
not work though.

Is this a bug or is the documentation incorrect?

Cheers,
Arne

hyperandroid

unread,
Jan 19, 2013, 3:36:03 PM1/19/13
to caa...@googlegroups.com

you are misssing the point that zindex is an immediate property.
by setting number.maxvalue caat reassings a valid naximum zindex. zero in your case where the container has only one element.
zindex is directly translated to order in the container children list.
all the UI i know about (java swing, adobe flex, etc.) work this way.
what they have is a layered container which keeps children sorted in different zindex collections.
for your sample to work, add both children, then set zorder/zindex (use them interchangeably).

- ibon

Arne Brutschy

unread,
Jan 20, 2013, 7:37:34 AM1/20/13
to caa...@googlegroups.com, hypera...@gmail.com
Thanks, that's what I feared. :) Problem is that I am dynamically
adding children and I kind of hoped that I could declare parts of the
display to be layered higher than these children.

Arne

MIhail Ilinov

unread,
Feb 2, 2013, 8:00:32 AM2/2/13
to caa...@googlegroups.com, hypera...@gmail.com
Hi, i am new to CAAT but i like what i see.

On this topic, and about dynamic creation of children, here my toughs in pseudo code:

createSomeParts();
scene.addChild(SomeParts);

loop() {
createChildrens();
scene.addChild(SomeParts);
}

//after that setting corresponding z-index

Case1. You want all actors from SomeParts to be always over

Just iterate over  SomeParts and set their z-index

Case2. You want some of the createChildresn to be always over

In the loop when creating them - add some marker property or add them to array and the iterate
over marked/array - and set the new z-index only to them, making them be on top of all others

I'll be happy to hear, your opinion about this plan and structure




Arne Brutschy

unread,
Feb 4, 2013, 8:35:28 AM2/4/13
to caa...@googlegroups.com, mike...@gmail.com, hypera...@gmail.com

I assume that you meant to say

loop() {
createChildrens();
scene.addChild(Children);
}

In case 1 your proposal is exactly what we're doing now. Works fine.

In case 2 you don't have to do anything - as scene.addChild(Children)
is called after scene.addChild(SomeParts), the former have
automatically a higher z-index than the latter.

Cheers,
Arne

Eric Suau

unread,
Dec 24, 2015, 6:03:11 AM12/24/15
to CAAT javascript framework, abru...@xylon.de
Sorry for resurecting a old thread !

I worked (debugging) with the setZOrder issue, see here : https://groups.google.com/forum/#!topic/caat-discuss/Tdl5wn37b_o
making short : 
using zOrder causes : 
 - Nothing ... :-(  
 - or message "Uncaught TypeError: actor.animate is not a function"
 - or message "Uncaught TypeError: child.findActorAtPosition is not a function"

found a bug in (ActorContainer or scene).setZOrder function

search setZOrder in caat.js
 on bottom, seek  these lines
   ...
       else {
                    var nActor= this.childrenList.splice(actorPos,1);
                    if ( index<0 ) {
                        index=0;
                    } else if ( index>this.childrenList.length ) {
                        index= this.childrenList.length;
                    }
                    //-- ERROR is HERE ---> this.childrenList.splice( index, 1, nActor );
       this.childrenList.splice(  index, 0,nActor[0] ); // Correction
                }

splice (index, 1, xxx) is a replacement (not an insertion)
the goal, in this portion of code is 
  - remove the actor in childrens array
  - put (insert) the actor at the newindex (or on last index if too high, or on first if too low)
  using splice is splice (index, 0 (for insertion, else is a replacement !), and element (not array of element) )

if this can help somenone...
best regards


Reply all
Reply to author
Forward
0 new messages