// Phaser.Physics.Arcade.PhysicsGroup var ArcadeSprite = require('./ArcadeSprite'); var Class = require('../../utils/Class'); var CONST = require('./const'); var GetFastValue = require('../../utils/object/GetFastValue'); var Group = require('../../gameobjects/group/Group'); var PhysicsGroup = new Class({ Extends: Group, initialize: function PhysicsGroup (world, scene, children, config) { if (config === undefined && !Array.isArray(children) && typeof children === 'object') { config = children; children = null; } else if (config === undefined) { config = {}; } this.world = world; config.createCallback = this.createCallback; config.removeCallback = this.removeCallback; config.classType = GetFastValue(config, 'classType', ArcadeSprite); this.physicsType = CONST.DYNAMIC_BODY; this.defaults = { setCollideWorldBounds: GetFastValue(config, 'collideWorldBounds', false), setAccelerationX: GetFastValue(config, 'accelerationX', 0), setAccelerationY: GetFastValue(config, 'accelerationY', 0), setBounceX: GetFastValue(config, 'bounceX', 0), setBounceY: GetFastValue(config, 'bounceY', 0), setDragX: GetFastValue(config, 'dragX', 0), setDragY: GetFastValue(config, 'dragY', 0), setGravityX: GetFastValue(config, 'gravityX', 0), setGravityY: GetFastValue(config, 'gravityY', 0), setFrictionX: GetFastValue(config, 'frictionX', 0), setFrictionY: GetFastValue(config, 'frictionY', 0), setVelocityX: GetFastValue(config, 'velocityX', 0), setVelocityY: GetFastValue(config, 'velocityY', 0), setAngularVelocity: GetFastValue(config, 'angularVelocity', 0), setAngularAcceleration: GetFastValue(config, 'angularAcceleration', 0), setAngularDrag: GetFastValue(config, 'angularDrag', 0), setMass: GetFastValue(config, 'mass', 1), setImmovable: GetFastValue(config, 'immovable', false) }; Group.call(this, scene, children, config); }, createCallback: function (child) { if (!child.body) { this.world.enableBody(child, CONST.DYNAMIC_BODY); } var body = child.body; for (var key in this.defaults) { body[key](this.defaults[key]); } }, removeCallback: function (child) { if (child.body) { this.world.disableBody(child); } }, setVelocity: function (x, y, step) { if (step === undefined) { step = 0; } var items = this.getChildren(); for (var i = 0; i < items.length; i++) { items[i].body.velocity.set(x + (i * step), y + (i * step)); } return this; }, setVelocityX: function (value, step) { if (step === undefined) { step = 0; } var items = this.getChildren(); for (var i = 0; i < items.length; i++) { items[i].body.velocity.x = value + (i * step); } return this; }, setVelocityY: function (value, step) { if (step === undefined) { step = 0; } var items = this.getChildren(); for (var i = 0; i < items.length; i++) { items[i].body.velocity.y = value + (i * step); } return this; } }); module.exports = PhysicsGroup;