Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

'Neighbors' error


files___
 Share

Recommended Posts

Hi folks, I get this error:

Uncaught TypeError: Cannot read property ‘neighbors’ of undefined

 

I read around and I think is something relative to constraint. I have two sprite with a constraint and I need to destroy all when I press a button. Maybe that's the problem!

Someone who could help me?!

Link to comment
Share on other sites



function hideDetail() { 
    var detail = {
        videoPath: null
        , cmd: true
        , arcObj: null
    };
    if (layerObjArray[getActualScene()].type == "immagine") playImmagine(detail, detail.cmd);
    else if (layerObjArray[getActualScene()].type == "text") playDetail(detail, cmd)
}

function playDetail(videoData, cmd) {
    var internalFun = {
            renderImage2: function (videoData, cmd) {
                console.log("ENTRATO SE  NON ESISTE UNA IMMAGINE");
                var scena = "scenaDetail";
                addLayer(scena, videoData.arcObj);
                var backLayer = game.add.group();
                var frontLayer = game.add.group();
                layerObjArray[scena].backLayer = backLayer;
                layerObjArray[scena].frontLayer = frontLayer;
                layerObjArray[scena].type = "text";
                var layerData = layerObjArray[scena];
                if ((layerObjArray[scena].architect.stopAudioOnStart) && (globalAudio))
                    if (audioArray["suono_background"] != "undefined") {
                        audioArray["suono_background"].fadeOut(1000);
                    }
                var screenBack = game.add.graphics();
                screenBack.beginFill(layerObjArray[scena].architect.backgroundColor, layerObjArray[scena].architect.backAlpha);
                screenBack.drawRect(0, 0, game.world.width, game.world.height);
                var labelDomanda = game.add.sprite(0, 0, screenBack.generateTexture(), 'back', layerObjArray[scena].backLayer);
                screenBack.destroy();
                var group = game.add.group();
                //createRope(14, game.width/2, 0, scena, group);
                var length = 16;
                var xAnchor = game.width / 2;
                var yAnchor = 0;
                var lastRect;
                //var newRect;
                var height = 20; //  Height for the physics body - your image height is 8px
                var width = 16; //  This is the width for the physics body. If too small the rectangles will get scrambled together.
                var maxForce = 29000; //  The force that holds the rectangles together.
                //game.physics.p2.gravity.y = 2000;
                //   game.physics.p2.restitution = 0.8;
                for (var i = 0; i <= length; i++) {
                    var x = xAnchor; //  All rects are on the same x position
                    var y = yAnchor + (i * height); //  Every new rect is positioned below the last
                    if (i % 2 === 0) {
                        if (i == length) {
                            /* var text=domandaObj.text.toUpperCase();
                                var dime=adattaDimeTesto(domandaObj.text,question.w,question.maxh);


                                var boxDomanda = this.game.add.graphics();
                                question.textStyle["wordWrapWidth"]=question.w;
                                question.textStyle["font"]=dime.fontsize+"px Arial";*/
                            console.log("Valore3 i: " + i);
                            var newRect2 = game.add.sprite(x, y, layerObjArray[scena].architect.gid, 0, group);
                            var textobj = game.add.text(0, 0, videoData.text, layerObjArray[scena].architect.labelStyle, group);
                            textobj.anchor.set(0.5);
                            game.physics.p2.enable(newRect, false, true);
                            newRect2.addChild(textobj);
                            newRect2.bringToTop();
                            game.physics.p2.enable(newRect2, false, false);
                            //  newRect2.body.velocity.y = 0;      //  Give it a push :) just for fun
                            newRect2.body.velocity.x = 10;
                            newRect2.body.mass = 2;
                            game.physics.p2.createRevoluteConstraint(newRect, [0, 0], newRect2, [0, 0], maxForce);
                            newRect2.sendToBack();
                        }
                        else {
                            console.log("Valore2 i: " + i);
                            //  Add sprite (and switch frame every 2nd time)
                            var newRect = game.add.sprite(x, y, 'chain', 1, group);
                        }
                    }
                    else {
                        console.log("Valore1 i: " + i);
                        var newRect = game.add.sprite(x, y, 'chain', 0, group);
                        newRect.bringToTop();
                    }
                    //  Enable physicsbody
                    game.physics.p2.enable(newRect, false, true);
                    //  Set custom rectangle
                    newRect.body.setRectangle(width, height);
                    if (i === 0) {
                        newRect.body.static = true;
                    }
                    else {
                        //  Anchor the first one created
                        newRect.body.velocity.y = 50; //  Give it a push :) just for fun
                        newRect.body.velocity.x = 5;
                        newRect.body.mass = length / i; //  Reduce mass for evey rope element
                    }
                    //  After the first rectangle is created we can add the constraint
                    if (lastRect) {
                        game.physics.p2.createRevoluteConstraint(newRect, [0, -10], lastRect, [0, 10], maxForce);
                    }
                    lastRect = newRect;
                }
                console.log("GRUPPO: " + group.length);
                //var sprite = group.create(game.world.centerX, game.world.centerY, layerObjArray[scena].architect.gid);
                //sprite.anchor.set(0.5,0.5);
                layerObjArray[scena].frontLayer.add(group);
                layerObjArray[scena].layer.add(layerData.backLayer);
                layerObjArray[scena].layer.add(layerData.frontLayer);
            }
        }
        // se non in overlay mettere qui la  closePrevWithTransition();
    var cmd = videoData.cmd;
    var varIsDeclared = true;
    try {
        layerObjArray["scenaDetail"].layer;
    }
    catch (e) {
        // console.log(e.name);
        if ((e.name == "ReferenceError") || (e.name == "TypeError")) {
            varIsDeclared = false;
        }
    }
    if (varIsDeclared == true) // se esiste gia
    {
        console.log("ENTRATO SE ESISTE GIA UNA IMMAGINE 1");
        var scena = getActualScene();
        var layerData = layerObjArray[scena];
        console.log("cmd=" + cmd);
        if (cmd === false) {
            console.log("transizione 2");
            closePrevWithTransition(function () {
                console.log("transizione 2.1");
                playDetail(videoData, cmd);
            }, false);
        }
        else if (cmd == true) {
            console.log("cancello tutto 3");
            // clearWithTransition();
            clearWithTransition(layerObjArray[scena].layer.frontLayer);
        }
    }
    else if ((varIsDeclared == false) && (cmd !== true)) // se non esiste
    {
        console.log("porca troia 0");
        /*if (layerObjArray[getActualScene()]!=undefined)
            clearWithTransitionWithCAll(function(){
                   console.log("porca troia 2");
                   internalFun.renderImage2(videoData,cmd);

               });*/
        // else
        internalFun.renderImage2(videoData, cmd);
    } //chiudo l'else
}

function clearWithTransition(layer,callbackFnk)
{
    console.log("LAYER CLEAR:" + layer);
    if (getActualScene()!=null)
    {    var scena=getActualScene();

            transition(scena,layerObjArray[scena].architect.transitionType,layerObjArray[scena].architect.transitionTime,function(){
                fadeAll();

                if(typeof callbackFnk !=undefined)
                 if (typeof callbackFnk == 'function') {
                                    callbackFnk.call(this);
                }
                else

                return true;

            },layer);

    }




}




function transition(scena,type,time,callbackFnk,layer)
{    //lo shaking e e l'effeto flash di tutta la visuale si può fare con l'oggetto camera
    //game.add.tween(layerObjArray[scena].layer).to( { x: +800 }, 1000, Phaser.Easing.Linear.Out, true);
console.log("ENTRO TRANS");
    console.log(type);
    var  existLayer=false;

    var servedLayer=null;
    if (layer!=undefined)
        {
            if (type=="scaleOut")
                {
                    type="none";
                    console.log("ATTENZIONE SI è SPECIFICATO UN LAYER IN UNA TRANSIZIONE E NON PUO' ESSERE USATA LA SCALEOUT APIENO SCHERMO IMPOSTATO IL TYPE A NONE");

                }
               existLayer=true;
                    servedLayer=layer;

        }
    else
        servedLayer=layerObjArray[scena].layer;


    if (type=="scaleOut")
        {

            var bmd = game.add.bitmapData(game.width, game.height);
            var bmdContainer = bmd.addToWorld(game.width, game.height, 0, 0, 0, 0);
            //bmd.drawFull(game.world);
            bmd.drawFull(layerObjArray[scena].layer);
            var worldx = game.add.sprite(0, 0, bmd.generateTexture(),'worldx');
            //game.add.tween( worldx.scale).to( { x: 0, y:0 }, time, Phaser.Easing.Linear.Out, true);
            layerObjArray[scena].layer.destroy();
            if (!existLayer) destroyLayer(scena);



            game.add.tween(worldx.scale).to( { x: 0, y: 0 }, time, Phaser.Easing.Linear.None, true);
            game.add.tween(worldx.position).to( { x:  worldx.width / 2, y:  worldx.height / 2}, time, Phaser.Easing.Linear.None, true ).onComplete.add(function(){
                worldx.destroy();

                 //layerObjArray[scena].layer.remove();

                if (typeof callbackFnk == 'function') {
                        callbackFnk.call(this);
                        }


            });



        }
    else if (type=="outLeft")
        {
            game.add.tween(servedLayer).to( { x: -game.world.width }, time, Phaser.Easing.Linear.Out, true).onComplete.add(function(){
                servedLayer.destroy();
                //game.world.removeAll();
                if (!existLayer) destroyLayer(scena);

                 if (typeof callbackFnk == 'function') {
                        callbackFnk.call(this);
                }


            });
        }
    else if (type=="outRight")
        {
            game.add.tween(servedLayer).to( { x: +game.world.width }, time, Phaser.Easing.Linear.Out, true).onComplete.add(function(){
                servedLayer.destroy();
                if (!existLayer) destroyLayer(scena);

                 if (typeof callbackFnk == 'function') {
                        callbackFnk.call(this);
                        }

            });
        }
    else if (type=="outUp")
        {
            game.add.tween(servedLayer).to( { y: -game.world.height }, time, Phaser.Easing.Linear.Out, true).onComplete.add(function(){
                servedLayer.destroy();
                destroyLayer(scena);
                 if (typeof callbackFnk == 'function') {
                        callbackFnk.call(this);
                        }

            });
        }
    else if (type=="outDown")
        {
            game.add.tween(servedLayer).to( { y: -game.world.height }, time, Phaser.Easing.Linear.Out, true).onComplete.add(function(){
                servedLayer.destroy();
                if (!existLayer) destroyLayer(scena);
                 if (typeof callbackFnk == 'function') {
                        callbackFnk.call(this);
                        }

            });
        }
    else if (type=="fadeOut")
        {
            game.add.tween(servedLayer).to( { alpha: 0  }, time, Phaser.Easing.Linear.Out, true).onComplete.add(function(){
                servedLayer.destroy();
                if (!existLayer) destroyLayer(scena);
                 if (typeof callbackFnk == 'function') {
                        callbackFnk.call(this);
                        }

            });
        }
    else if (type=="none")
        {

                servedLayer.destroy();
            //layerObjArray[scena].backLayer.destroy();
                if (!existLayer) destroyLayer(scena);
                if (typeof callbackFnk == 'function') {
                        callbackFnk.call(this);
                        }


        }


}



function destroyLayer(nomeScena)
{
 console.log("distruggo il layer-------------------------------");
 //console.log(layerObjArray);
 //   console.log(layerObjArray.length);

    //for (i=0;i<layerObjArray.length;i++)
   // {
      //  console.log(layerObjArray[i]);
   // }

    for (i=0;i<layerObjArray.length;i++)
    {  //console.log("controllo cosa distrugge "+nomeScena);
       //console.log("controllo dentro l'oggetto "+layerObjArray[layerObjArray[i]].layer_name);
      //  console.log(layerObjArray[layerObjArray[i]].layer_name+"=="+nomeScena);


       if (layerObjArray[layerObjArray[i]].layer_name==nomeScena)
           {
               //console.log("elimino il layer");
            //delete layerObjArray[i];
                layerObjArray.splice(i, 1);
            delete layerObjArray[nomeScena];

                console.log("check se eliminaaaaaaaaa");
               console.log( layerObjArray);
               break;

           }

    }
    //console.log("stampa oggetto riga 481");
    //console.log(layerObjArray);
    return true;
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...