API Documentation for: 0.11.10
Show:

File:src\CollisionData.js

                        /**
                         * CollisionData holds collision data passed to entities during collisions with other entities. This class is primarily used by the ["HandlerCollision"]("HandlerCollision"%20Component.html) Component to trigger messages on child entities as collision occur.
                         *
                         * @namespace platypus
                         * @class CollisionData
                         * @constructor
                         * @param occurredOrData {Boolean|CollisionData} Whether this represents an actual collision between two shapes. If a CollisionData instance is provided, the instance's full set of values are copied.
                         * @param direction {Number} 1 or -1 to define the direction of the collision.
                         * @param position {Number} A positive number describing position along the line of collision direction.
                         * @param deltaMovement {Number} A positive number describing the magnitude of overlap.
                         * @param aABB {platypus.AABB} An AABB of the colliding shape.
                         * @param thisShape {platypus.Shape} The moving shape.
                         * @param thatShape {platypus.Shape} The stationary shape being collided with.
                         * @param vector {platypus.Vector} The vector describing the contact point.
                         * @param stuck {Number} The amount of unwarranted overlap if shapes start in a collided position before moving.
                         * @return {platypus.CollisionData} Returns the new CollisionData object.
                         */
                        /*global include, platypus, recycle, springroll */
                        platypus.CollisionData = (function () {
                            'use strict';
                            
                            var Vector = include('platypus.Vector'),
                                CollisionData = function (occurredOrData) {
                                    if (!this.vector) {
                                        this.vector = Vector.setUp();
                                    }
                                    if (occurredOrData instanceof CollisionData) {
                                        this.copy(occurredOrData);
                                    } else {
                                        this.set.apply(this, arguments);
                                    }
                                },
                                proto = CollisionData.prototype;
                            
                            /**
                             * Sets all of the properties of the CollisionData.
                             *
                             * @method set
                             * @param occurred {Boolean} Whether this represents an actual collision between two shapes.
                             * @param direction {Number} 1 or -1 to define the direction of the collision.
                             * @param position {Number} A positive number describing position along the line of collision direction.
                             * @param deltaMovement {Number} A positive number describing the magnitude of overlap.
                             * @param aABB {platypus.AABB} An AABB of the colliding shape.
                             * @param thisShape {platypus.Shape} The moving shape.
                             * @param thatShape {platypus.Shape} The stationary shape being collided with.
                             * @param vector {platypus.Vector} The vector describing the contact point.
                             * @param stuck {Number} The amount of unwarranted overlap if shapes start in a collided position before moving.
                             * @since 0.8.7
                             */
                            proto.set = function (occurred, direction, position, deltaMovement, aABB, thisShape, thatShape, vector, stuck) {
                                this.occurred = occurred || false;
                                this.direction = direction || null;
                                this.position = position || null;
                                this.deltaMovement = deltaMovement || null;
                                this.aABB = aABB || null;
                                this.thisShape = thisShape || null;
                                this.thatShape = thatShape || null;
                                this.vector.set(vector);
                                this.stuck  = stuck || 0;
                            };
                        
                            /**
                             * Sets all of the properties of the CollisionData to match those of the provided CollisionData object.
                             *
                             * @method copy
                             * @param dataToCopy {CollisionData} The object values to copy.
                             */
                            proto.copy = function (dataToCopy) {
                                this.occurred         = dataToCopy.occurred;
                                this.direction         = dataToCopy.direction;
                                this.position         = dataToCopy.position;
                                this.deltaMovement     = dataToCopy.deltaMovement;
                                this.aABB             = dataToCopy.aABB;
                                this.thisShape      = dataToCopy.thisShape;
                                this.thatShape      = dataToCopy.thatShape;
                                this.vector.setVector(dataToCopy.vector);
                                this.stuck          = dataToCopy.stuck;
                            };
                        
                            /**
                             * Returns an collisionData from cache or creates a new one if none are available.
                             *
                             * @method CollisionData.setUp
                             * @return {platypus.CollisionData} The instantiated CollisionData.
                             * @since 0.8.7
                             */
                            /**
                             * Returns a collisionData back to the cache.
                             *
                             * @method CollisionData.recycle
                             * @param collisionData {platypus.CollisionData} The collisionData to be recycled.
                             * @since 0.8.7
                             */
                            /**
                             * Relinquishes properties of the collisionData and recycles it.
                             *
                             * @method recycle
                             * @since 0.8.7
                             */
                            recycle.add(CollisionData, !!springroll.Debug, 'CollisionData');
                            
                            return CollisionData;
                        }());