nak3ddogs Posted July 16, 2014 Share Posted July 16, 2014 helo. the ball.scale scale the ball's velocity and i cant stop the ball's x movement antway.why?thx for any advance function createGround() { var ball = this.add.sprite(this.menu_group.x - this.bg_popup.width/2 + this.bg_popup.width * Math.random(), this.menu_group.y + this.bg_popup.height/2 - 20, 'ground'); this.physics.enable(ball, Phaser.Physics.ARCADE); scale = this.rnd.realInRange(0.2, 2); ball.scale.x = scale; ball.scale.y = scale; ball.anchor.setTo(0.5,0.5); ball.angle = 360 * Math.random(); ball.body.gravity.y = 500; ball.body.maxVelocity.y = 200; ball.body.maxVelocity.x = 0; ball.outOfBoundsKill = true; this.time.events.add(2000 * Math.random(), createGround, this); } this.time.events.add(1000, createGround, this); Link to comment Share on other sites More sharing options...
lewster32 Posted July 16, 2014 Share Posted July 16, 2014 Anything you do to potentially alter the ball's position will result in the physics system trying to interpret that sudden movement as a change in velocity. You can either try to enable physics after doing all of your anchor/scale stuff, or just zero the velocity when you're done. nak3ddogs 1 Link to comment Share on other sites More sharing options...
Skell Posted July 16, 2014 Share Posted July 16, 2014 The physical body is created based on the size, angle sprite anchor - because calculated body center mass.function createGround() { var ball = this.add.sprite(this.menu_group.x - this.bg_popup.width/2 + this.bg_popup.width * Math.random(), this.menu_group.y + this.bg_popup.height/2 - 20, 'ground'); scale = this.rnd.realInRange(0.2, 2); ball.scale.set(scale, scale); ball.anchor.setTo(0.5,0.5); ball.angle = 360 * Math.random(); this.physics.enable(ball, Phaser.Physics.ARCADE); ball.body.gravity.y = 500; ball.body.maxVelocity.y = 200; ball.body.maxVelocity.x = 0; ball.outOfBoundsKill = true; this.time.events.add(2000 * Math.random(), createGround, this); } or ball.body.velocity.set(0,0); - zero the velocity lewster32 1 Link to comment Share on other sites More sharing options...
nak3ddogs Posted July 16, 2014 Author Share Posted July 16, 2014 the ball.body.velocity.set(0,0) not worked but when i applied the physics after scale the problem have solved.ty buddies lewster32 1 Link to comment Share on other sites More sharing options...
Recommended Posts