Sign in to follow this  
nak3ddogs

scale transform velocity

Recommended Posts

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);

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

 

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.