API Docs for: 0.1.0
Show:

File: cangaja/box2d/b2d-rectangle.js

                        /**
                         * @description
                         *
                         * B2DRectangle is a simple b2PolygonShape wrapper element with basic physics properties.
                         *
                         ```
                        
                         var e = new CG.B2DRectangle({
                           name: 'player',
                           image: this.asset.getImageByName('glowball'),
                           x: 100,
                           y: 100,
                           world: b2world,
                           scale: 40,
                           bodyType: box2d.b2BodyType.b2_staticBody
                         })
                        
                         ```
                         *
                         * @class CG.B2DRectangle
                         * @extends CG.B2DEntity
                         */
                        
                        CG.B2DEntity.extend('B2DRectangle', {
                            /**
                             * Options:
                             * name {string}
                             * image {mixed}
                             * x {number}
                             * y (number}
                             * world {object}
                             * scale {number}
                             * bodyType {box2d.b2BodyType}
                             *
                             * @method init
                             * @constructor
                             * @param options     {Object}
                             * @return {*}
                             */
                            init:function (options) {
                                this._super(options)
                                this.instanceOf = 'B2DRectangle'
                        
                                this.setImage(this.image)
                        
                                /**
                                 * @property fixDef.shape
                                 * @type {b2PolygonShape}
                                 */
                                this.fixDef.shape = new b2PolygonShape
                                this.fixDef.shape.SetAsBox(this.width / this.scale * 0.5, this.height / this.scale * 0.5)
                        
                                /**
                                 * @property bodyDef.type
                                 * @type {box2d.b2BodyType.b2_staticBody/box2d.b2BodyType.b2_dynamicBody/box2d.b2BodyType.b2_kinematicBody/box2d.b2BodyType.b2_bulletBody}
                                 */
                                this.bodyDef.type = this.bodyType
                        
                                /**
                                 * @property bodyDef.position.x
                                 * @type {Number}
                                 */
                                this.bodyDef.position.x = this.x / this.scale
                                /**
                                 * @property bodyDef.position.y
                                 * @type {Number}
                                 */
                                this.bodyDef.position.y = this.y / this.scale
                                /**
                                 * @property bodyDef.userData
                                 * @type {*}
                                 */
                                this.bodyDef.userData = this.id
                                /**
                                 * @property body
                                 * @type {b2Body}
                                 */
                                this.body = this.world.CreateBody(this.bodyDef)
                                this.body.CreateFixture(this.fixDef)
                        
                                return this
                            }
                        })