Sarahjdes Posted June 30, 2014 Share Posted June 30, 2014 My question is pretty simple : what is the difference between sprite gravity and game gravity? Like these : this.game.physics.arcade.gravity.y = 300;this.player.body.gravity.y = 300;From what I understand, game gravity will be applied to all my sprites, while I would have to specify it for every sprite if I use the sprite gravity. Is that right? Looking at the following example, I understand the behavior of sprite1 and sprite4, but not the other two. (Last time I took physics classes was 5 years ago.) How do they work exactly? http://examples.phaser.io/_site/view_full.html?d=arcade%20physics&f=gravity.js&t=gravity Thanks! Link to comment Share on other sites More sharing options...
lewster32 Posted June 30, 2014 Share Posted June 30, 2014 The docs specify what this does: A local gravity applied to this Body. If non-zero this over rides any world gravity, unless Body.allowGravity is set to false. Link to comment Share on other sites More sharing options...
Sarahjdes Posted June 30, 2014 Author Share Posted June 30, 2014 I'm still not sure I understand this example the following example. What does « Sprite 3 will use both the world gravity and its own gravityScale modifier » mean? I don't see how it is different from Sprite 2. // Set the world (global) gravitygame.physics.arcade.gravity.y = 100;// Sprite 1 will use the World (global) gravitysprite1 = game.add.sprite(100, 96, 'ilkke');// Sprite 2 is set to ignore the global gravity and use its own valuesprite2 = game.add.sprite(300, 96, 'ilkke');// Sprite 3 will use both the world gravity and its own gravityScale modifiersprite3 = game.add.sprite(500, 96, 'ilkke');// Sprite 4 will ignore all gravitysprite4 = game.add.sprite(700, 96, 'ilkke');// Enable physics on those spritesgame.physics.enable( [ sprite1, sprite2, sprite3, sprite4 ], Phaser.Physics.ARCADE);sprite1.body.collideWorldBounds = true;sprite1.body.bounce.y = 0.8;sprite2.body.collideWorldBounds = true;sprite2.body.bounce.y = 0.8;sprite2.body.gravity.y = 200;sprite3.body.collideWorldBounds = true;sprite3.body.bounce.y = 0.8;sprite3.body.gravity.y = 50;sprite4.body.allowGravity = false; Link to comment Share on other sites More sharing options...
lewster32 Posted June 30, 2014 Share Posted June 30, 2014 Hmm, I think that example is at fault and confusing matters; it's possibly been updated from some old version of the physics engine but not fully, as apart from the value sprites 2 and 3 are basically the same, they will both use their own gravity instead of world gravity. Link to comment Share on other sites More sharing options...
Sarahjdes Posted July 2, 2014 Author Share Posted July 2, 2014 This makes sense then. Thanks for clearing that out! Link to comment Share on other sites More sharing options...
Recommended Posts