src/spatial/2d.js
function(name, value) {
        // Return if there is no change
        if (this[name] === value) {
            return;
        }
        //keep a reference of the old positions
        var old = Crafty.rectManager._pool.copy(this);

        var mbr;
        //if rotation, use the rotate method
        if (name === "_rotation") {
            this._rotate(value); // _rotate triggers "Rotate"
            //set the global Z and trigger reorder just in case
        } else if (name === "_x" || name === "_y") {
            // mbr is the minimal bounding rectangle of the entity
            mbr = this._mbr;
            if (mbr) {
                mbr[name] -= this[name] - value;
                // cbr is a non-minimal bounding rectangle that contains both hitbox and mbr
                // It will exist only when the collision hitbox sits outside the entity
                if (this._cbr) {
                    this._cbr[name] -= this[name] - value;
                }
            }
            this[name] = value;

            this.trigger("Move", old);
        } else if (name === "_h" || name === "_w") {
            mbr = this._mbr;

            var oldValue = this[name];
            this[name] = value;
            if (mbr) {
                this._calculateMBR();
            }
            if (name === "_w") {
                this.trigger("Resize", {
                    axis: "w",
                    amount: value - oldValue
                });
            } else if (name === "_h") {
                this.trigger("Resize", {
                    axis: "h",
                    amount: value - oldValue
                });
            }
            this.trigger("Move", old);
        } else if (name === "_z") {
            var intValue = value << 0;
            value = value === intValue ? intValue : intValue + 1;
            this._globalZ = value * 100000 + this[0]; //magic number 10^5 is the max num of entities
            this[name] = value;
            this.trigger("Reorder");
        }

        //everything will assume the value
        this[name] = value;

        // flag for redraw
        this.trigger("Invalidate");

        Crafty.rectManager._pool.recycle(old);
    }
function(name, value) {
        // Return if there is no change
        if (this[name] === value) {
            return;
        }
        //keep a reference of the old positions
        var old = Crafty.rectManager._pool.copy(this);

        var mbr;
        //if rotation, use the rotate method
        if (name === "_rotation") {
            this._rotate(value); // _rotate triggers "Rotate"
            //set the global Z and trigger reorder just in case
        } else if (name === "_x" || name === "_y") {
            // mbr is the minimal bounding rectangle of the entity
            mbr = this._mbr;
            if (mbr) {
                mbr[name] -= this[name] - value;
                // cbr is a non-minimal bounding rectangle that contains both hitbox and mbr
                // It will exist only when the collision hitbox sits outside the entity
                if (this._cbr) {
                    this._cbr[name] -= this[name] - value;
                }
            }
            this[name] = value;

            this.trigger("Move", old);
        } else if (name === "_h" || name === "_w") {
            mbr = this._mbr;

            var oldValue = this[name];
            this[name] = value;
            if (mbr) {
                this._calculateMBR();
            }
            if (name === "_w") {
                this.trigger("Resize", {
                    axis: "w",
                    amount: value - oldValue
                });
            } else if (name === "_h") {
                this.trigger("Resize", {
                    axis: "h",
                    amount: value - oldValue
                });
            }
            this.trigger("Move", old);
        } else if (name === "_z") {
            var intValue = value << 0;
            value = value === intValue ? intValue : intValue + 1;
            this._globalZ = value * 100000 + this[0]; //magic number 10^5 is the max num of entities
            this[name] = value;
            this.trigger("Reorder");
        }

        //everything will assume the value
        this[name] = value;

        // flag for redraw
        this.trigger("Invalidate");

        Crafty.rectManager._pool.recycle(old);
    }
function ( name , value ) { // Return if there is no change if ( this [ name ] === value ) { return ; } //keep a reference of the old positions var old = Crafty . rectManager . _pool . copy ( this ) ; var mbr ; //if rotation, use the rotate method if ( name === "_rotation" ) { this . _rotate ( value ) ; // _rotate triggers "Rotate" //set the global Z and trigger reorder just in case } else if ( name === "_x" || name === "_y" ) { // mbr is the minimal bounding rectangle of the entity mbr = this . _mbr ; if ( mbr ) { mbr [ name ] -= this [ name ] - value ; // cbr is a non-minimal bounding rectangle that contains both hitbox and mbr // It will exist only when the collision hitbox sits outside the entity if ( this . _cbr ) { this . _cbr [ name ] -= this [ name ] - value ; } } this [ name ] = value ; this . trigger ( "Move" , old ) ; } else if ( name === "_h" || name === "_w" ) { mbr = this . _mbr ; var oldValue = this [ name ] ; this [ name ] = value ; if ( mbr ) { this . _calculateMBR ( ) ; } if ( name === "_w" ) { this . trigger ( "Resize" , { axis : "w" , amount : value - oldValue } ) ; } else if ( name === "_h" ) { this . trigger ( "Resize" , { axis : "h" , amount : value - oldValue } ) ; } this . trigger ( "Move" , old ) ; } else if ( name === "_z" ) { var intValue = value << 0 ; value = value === intValue ? intValue : intValue + 1 ; this . _globalZ = value * 100000 + this [ 0 ] ; //magic number 10^5 is the max num of entities this [ name ] = value ; this . trigger ( "Reorder" ) ; } //everything will assume the value this [ name ] = value ; // flag for redraw this . trigger ( "Invalidate" ) ; Crafty . rectManager . _pool . recycle ( old ) ; }
This is a setter method for all 2D properties including x, y, w, h, and rotation.
This is a setter method for all 2D properties including x y w h and rotation .