src/graphics/layers.js
function(useCached) {
            var rect = this._cachedViewportRect;
            if (useCached) return rect;

            // total transform is viewport transform combined with this layer's transform
            var viewport = Crafty.viewport;
            var options = this.options;

            var scale = Math.pow(viewport._scale, options.scaleResponse);
            rect._scale = scale;
            rect._w = viewport._width / scale;
            rect._h = viewport._height / scale;

            // This particular transformation is designed such that,
            // if a combination pan/scale keeps the center of the screen fixed for a layer with x/y response of 1,
            // then it will also be fixed for layers with other values for x/y response
            // (note that the second term vanishes when either the response or scale are 1)
            rect._x =
                options.xResponse * -viewport._x -
                0.5 *
                    (options.xResponse - 1) *
                    (1 - 1 / scale) *
                    viewport._width;
            rect._y =
                options.yResponse * -viewport._y -
                0.5 *
                    (options.yResponse - 1) *
                    (1 - 1 / scale) *
                    viewport._height;

            return rect;
        }
function(useCached) {
            var rect = this._cachedViewportRect;
            if (useCached) return rect;

            // total transform is viewport transform combined with this layer's transform
            var viewport = Crafty.viewport;
            var options = this.options;

            var scale = Math.pow(viewport._scale, options.scaleResponse);
            rect._scale = scale;
            rect._w = viewport._width / scale;
            rect._h = viewport._height / scale;

            // This particular transformation is designed such that,
            // if a combination pan/scale keeps the center of the screen fixed for a layer with x/y response of 1,
            // then it will also be fixed for layers with other values for x/y response
            // (note that the second term vanishes when either the response or scale are 1)
            rect._x =
                options.xResponse * -viewport._x -
                0.5 *
                    (options.xResponse - 1) *
                    (1 - 1 / scale) *
                    viewport._width;
            rect._y =
                options.yResponse * -viewport._y -
                0.5 *
                    (options.yResponse - 1) *
                    (1 - 1 / scale) *
                    viewport._height;

            return rect;
        }
function ( useCached ) { var rect = this . _cachedViewportRect ; if ( useCached ) return rect ; // total transform is viewport transform combined with this layer's transform var viewport = Crafty . viewport ; var options = this . options ; var scale = Math . pow ( viewport . _scale , options . scaleResponse ) ; rect . _scale = scale ; rect . _w = viewport . _width / scale ; rect . _h = viewport . _height / scale ; // This particular transformation is designed such that, // if a combination pan/scale keeps the center of the screen fixed for a layer with x/y response of 1, // then it will also be fixed for layers with other values for x/y response // (note that the second term vanishes when either the response or scale are 1) rect . _x = options . xResponse * - viewport . _x - 0.5 * ( options . xResponse - 1 ) * ( 1 - 1 / scale ) * viewport . _width ; rect . _y = options . yResponse * - viewport . _y - 0.5 * ( options . yResponse - 1 ) * ( 1 - 1 / scale ) * viewport . _height ; return rect ; }
Based on the camera options, find the Crafty coordinates corresponding to the layer's position in the viewport
Based on the camera options find the Crafty coordinates corresponding to the layer s position in the viewport