function snapToCat(sprite, pointer) {
            if(Phaser.Geom.Intersects.RectangleToRectangle(sprite.getBounds(), cat.boundingBox)){
                sprite.getData('group').replace(sprite,blankSprite );
                sprite.ignoreDestroy = true;
                cat.getData('catLayer').add(sprite);
                
                // function to make sure that same article of clothing can't be placed on a cat twice
                function handleClothingPlacement(clothingPosition) {

                    // multiple clothes of same type cant be on cat
                    if (clothingPosition.currentClothing != null && clothingPosition.currentClothing != sprite) { 
                        returnSpritetoCloset(clothingPosition.currentClothing);
                    } 

                    //play a random clothing russle sound from the clothingrussles array of sounds
                    utilities.playSoundEffect(Phaser.Utils.Array.GetRandom(clothingRussles));

                    //set the position of the sprite 
                    sprite.x = clothingPosition.x;
                    sprite.y = clothingPosition.y;
                    sprite.setDepth(clothingPosition.z);
                    //set the clothPositions current clothing to be what was just dropped on it
                    clothingPosition.currentClothing = sprite;

                }
                //switch statement to handle multiple types of clothes
                switch (sprite.clothingType){
                    case clothingTypes.hat:
                        handleClothingPlacement(cat.hatPosition);    
                        break;
                    case clothingTypes.shoe:
                        handleClothingPlacement(cat.shoePosition); 
                        break;
                    case clothingTypes.shirt:
                        handleClothingPlacement(cat.shirtPosition); 
                        break;   
                    case clothingTypes.pants:
                        handleClothingPlacement(cat.pantsPosition); 
                        break;                                                 
                }
            }
            //Sprite shrinks and returns to closet if it is not dropped on cat.
            else{
                /*
                set the cat's clothing at this position to null to avoid crashing the game
                in the polaroid scene, if the sprite was on the cat
                */
                switch (sprite.clothingType){
                    case clothingTypes.hat:
                        if (cat.hatPosition.currentClothing === sprite){
                            cat.hatPosition.currentClothing = null;
                        }
                        break;
                    case clothingTypes.shoe:
                        if (cat.shoePosition.currentClothing === sprite){
                            cat.shoePosition.currentClothing = null;
                        }
                        break;
                    case clothingTypes.shirt:
                        if (cat.shirtPosition.currentClothing === sprite){
                            cat.shirtPosition.currentClothing = null;
                        }
                        break;   
                    case clothingTypes.pants:
                        if (cat.pantsPosition.currentClothing === sprite){
                            cat.pantsPosition.currentClothing = null;
                        }
                        break;                                                 
                }
                returnSpritetoCloset(sprite);
                
            }
        }
/*
        overlap check and snap. this now uses a custom bounding box that I attatched to the 
        cat in setupCat(). this seems to fix a lot of the bugs related to dragging back to closet
        and clothes snapping. you can adjust the bounding box in the setUpCat() function.
        */
overlap check and snap. this now uses a custom bounding box that I attatched to the
cat in setupCat(). this seems to fix a lot of the bugs related to dragging back to closet
and clothes snapping. you can adjust the bounding box in the setUpCat() function.
overlap check and snap . this now uses a custom bounding box that I attatched to the cat in setupCat () . this seems to fix a lot of the bugs related to dragging back to closet and clothes snapping . you can adjust the bounding box in the setUpCat () function .
function snapToCat(sprite, pointer) {
            if(Phaser.Geom.Intersects.RectangleToRectangle(sprite.getBounds(), cat.boundingBox)){
                sprite.getData('group').replace(sprite,blankSprite );
                sprite.ignoreDestroy = true;
                cat.getData('catLayer').add(sprite);
                function handleClothingPlacement(clothingPosition) {
                    if (clothingPosition.currentClothing != null && clothingPosition.currentClothing != sprite) { 
                        returnSpritetoCloset(clothingPosition.currentClothing);
                    } 
                    utilities.playSoundEffect(Phaser.Utils.Array.GetRandom(clothingRussles));
                    sprite.x = clothingPosition.x;
                    sprite.y = clothingPosition.y;
                    sprite.setDepth(clothingPosition.z);
                    clothingPosition.currentClothing = sprite;
                }
                switch (sprite.clothingType){
                    case clothingTypes.hat:
                        handleClothingPlacement(cat.hatPosition);    
                        break;
                    case clothingTypes.shoe:
                        handleClothingPlacement(cat.shoePosition); 
                        break;
                    case clothingTypes.shirt:
                        handleClothingPlacement(cat.shirtPosition); 
                        break;   
                    case clothingTypes.pants:
                        handleClothingPlacement(cat.pantsPosition); 
                        break;                                                 
                }
            }
            else{
                switch (sprite.clothingType){
                    case clothingTypes.hat:
                        if (cat.hatPosition.currentClothing === sprite){
                            cat.hatPosition.currentClothing = null;
                        }
                        break;
                    case clothingTypes.shoe:
                        if (cat.shoePosition.currentClothing === sprite){
                            cat.shoePosition.currentClothing = null;
                        }
                        break;
                    case clothingTypes.shirt:
                        if (cat.shirtPosition.currentClothing === sprite){
                            cat.shirtPosition.currentClothing = null;
                        }
                        break;   
                    case clothingTypes.pants:
                        if (cat.pantsPosition.currentClothing === sprite){
                            cat.pantsPosition.currentClothing = null;
                        }
                        break;                                                 
                }
                returnSpritetoCloset(sprite);
            }
        }
function snapToCat ( sprite , pointer ) { if ( Phaser . Geom . Intersects . RectangleToRectangle ( sprite . getBounds ( ) , cat . boundingBox ) ) { sprite . getData ( 'group' ) . replace ( sprite , blankSprite ) ; sprite . ignoreDestroy = true ; cat . getData ( 'catLayer' ) . add ( sprite ) ; function handleClothingPlacement ( clothingPosition ) { if ( clothingPosition . currentClothing != null && clothingPosition . currentClothing != sprite ) { returnSpritetoCloset ( clothingPosition . currentClothing ) ; } utilities . playSoundEffect ( Phaser . Utils . Array . GetRandom ( clothingRussles ) ) ; sprite . x = clothingPosition . x ; sprite . y = clothingPosition . y ; sprite . setDepth ( clothingPosition . z ) ; clothingPosition . currentClothing = sprite ; } switch ( sprite . clothingType ) { case clothingTypes . hat : handleClothingPlacement ( cat . hatPosition ) ; break ; case clothingTypes . shoe : handleClothingPlacement ( cat . shoePosition ) ; break ; case clothingTypes . shirt : handleClothingPlacement ( cat . shirtPosition ) ; break ; case clothingTypes . pants : handleClothingPlacement ( cat . pantsPosition ) ; break ; } } else { switch ( sprite . clothingType ) { case clothingTypes . hat : if ( cat . hatPosition . currentClothing === sprite ) { cat . hatPosition . currentClothing = null ; } break ; case clothingTypes . shoe : if ( cat . shoePosition . currentClothing === sprite ) { cat . shoePosition . currentClothing = null ; } break ; case clothingTypes . shirt : if ( cat . shirtPosition . currentClothing === sprite ) { cat . shirtPosition . currentClothing = null ; } break ; case clothingTypes . pants : if ( cat . pantsPosition . currentClothing === sprite ) { cat . pantsPosition . currentClothing = null ; } break ; } returnSpritetoCloset ( sprite ) ; } }
overlap check and snap.
overlap check and snap .
// function to make sure that same article of clothing can't be placed on a cat twice // multiple clothes of same type cant be on cat //play a random clothing russle sound from the clothingrussles array of sounds //set the position of the sprite  //set the clothPositions current clothing to be what was just dropped on it //switch statement to handle multiple types of clothes //Sprite shrinks and returns to closet if it is not dropped on cat. /*
                set the cat's clothing at this position to null to avoid crashing the game
                in the polaroid scene, if the sprite was on the cat
                */