Z-Order

14 views
Skip to first unread message

Eric Suau

unread,
Jul 1, 2013, 11:52:37 AM7/1/13
to caat-d...@googlegroups.com
unable to place a sprite on top of scene (or bottom). an issue ?

doc talk about zOrder : setZOrder (actor, zIndex), i think is prototyped for scene

// each sprite is 64x64
spriteA.setLocation(10,10);
spriteB.setLocation(30,30);
// so.. sprite1 and 2  overlap

// but
scene.setZOrder(spriteA,1);
scene.setZOrder(spriteB,2);

// as same effect as bellow
scene.setZOrder(spriteA,2);
scene.setZOrder(spriteB,1);

// no change with ...
scene.setZOrder(spriteA,10);
scene.setZOrder(spriteB,30);

// or this..
scene.setZOrder(spriteA,30);
scene.setZOrder(spriteB,10);

in all cases, spriteA is under spriteB, and i can't reverse display order ...







Eric Suau

unread,
Dec 24, 2015, 5:05:55 AM12/24/15
to caat discuss
 /*
       eric Suau 2015 dec 23
       I now.. is a old thread...
    
    pseudo code

    Correction For Caat.js 
    function setZorder don't work, or causes errors

 */

 /* simple init */
 director = (create director)
 scene    = director.createScene();
 director.loop(0); 

 /* 2 actors */

  element1=new CAAT.ImageActor(); // at least  50x50 pixels for overlap test
  element1.setImage(...).setLocation(10,10);
  element2=new CAAT.ImageActor();
  element2.setImage(...).setLocation(30,30); // overlapping element2 on top of element1

 /* adding actors to scene */

  scene.addChild(element1);
  scene.addChild(element2);

well....
  we have 2 elements
  [0]--> element 1
  [1]--> element 2

now an event to change the ZOrder...

 on..(what you want, button click, mouse over...) {
   scene.setZorder(element1,1);
      // or scene.setZorder(element1,1000); 
      // or scene.setZorder(element1,0);  // stay unchanged
 } 

the event cause an issue with messages bellow
 - Uncaught TypeError: actor.animate is not a function
 - Uncaught TypeError: child.findActorAtPosition is not a function
or at least, no error, but the zOrder stay unchanged.


now... check the setZOrder  in caat.js
--------------------------------------
       setZOrder : function( actor, index ) {
            var actorPos= this.findChild(actor);
            // the actor is present
            if ( -1!==actorPos ) {
                // trivial reject.
                if ( index===actorPos ) {
                    return;
                }
                if ( index>=this.childrenList.length ) {
this.childrenList.splice(actorPos,1);
this.childrenList.push(actor);
                } 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
                }
            }
        }
};
------------------------------------

  this.childrenList.splice( index, 1, nActor );
   replaces 1 element of children by an element that is an array (not elements inside the array !)
  Solution  : 
   nActor is always sized to 1  (see : var nActor= this.childrenList.splice(actorPos,1);)
   so, the correct inserting way is
     this.childrenList.splice( index Where Replace , 0 (and not >0 !!!, see javacript > 1.2 documentation) , nActor[0] (the element, not the array );

----------------------------------------
   tested in scene, or containerActor, works as expected  like a charm !
  
  Can someone confirm ?

 
Reply all
Reply to author
Forward
0 new messages