goshki Posted April 2, 2014 Share Posted April 2, 2014 Hi, I have a scene where a global gravity for Arcade Physics is set to 640. Then I try to set a lower gravity of 10 for a specific particle emitter, so to have the particles seem to float in the air.game.physics.startSystem(Phaser.Physics.ARCADE);// 1. Setting global gravity.game.physics.arcade.gravity.y = 640;game.physics.arcade.frameRate = 1 / 30;game.time.deltaCap = 1 / 30 * 2;emitter = game.add.emitter(0, 0, 100);emitter.makeParticles('particle');// 2. Overriding gravity for particle emitter.// Won't have any effect because of 1.emitter.gravity = 10;But it seems that it's not possible to override the emitter gravity if the global gravity is set. Commenting out game.physics.arcade.gravity.y = 640; makes the particles float in the air as expected. I've attached a test project showing the problem in action.phaser-2.0.2-overriding-particle-gravity.zip Link to comment Share on other sites More sharing options...
goshki Posted April 2, 2014 Author Share Posted April 2, 2014 I've checked Phaser source code and it seems that body gravity does not override but is added to global gravity./*** A tween-like function that takes a starting velocity and some other factors and returns an altered velocity.* Based on a function in Flixel by @ADAMATOMIC** @method Phaser.Physics.Arcade#computeVelocity* @param {number} axis - 0 for nothing, 1 for horizontal, 2 for vertical.* @param {Phaser.Physics.Arcade.Body} body - The Body object to be updated.* @param {number} velocity - Any component of velocity (e.g. 20).* @param {number} acceleration - Rate at which the velocity is changing.* @param {number} drag - Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.* @param {number} [max=10000] - An absolute value cap for the velocity.* @return {number} The altered Velocity value.*/computeVelocity: function (axis, body, velocity, acceleration, drag, max) { max = max || 10000; if (axis == 1 && body.allowGravity) { velocity += (this.gravity.x + body.gravity.x) * this.game.time.physicsElapsed; } else if (axis == 2 && body.allowGravity) { velocity += (this.gravity.y + body.gravity.y) * this.game.time.physicsElapsed; } Is this by design? Link to comment Share on other sites More sharing options...
Recommended Posts