# Performance issues

## Recommended Posts

Hey all,

Im currently having some perf issues on a roulette game Im making. Im just trying to move the ball around a track(more of an oval than a circle). It starts to lag every now and then though. Any ideas on what might cause this? According to the  Chrome profile it looks like the draws are taking really long some times...any optimization ideas? Also, there seems to be quite a bit of GC-ing going on, even though Im not creating anything?

Here is the math I am using to calculate the balls position. This happens every tick, although I cant see why this would slow down the device:

`_updateBall() {		this._loopProgress = this._startProgress + this._timePassed / this._settings.timeLoop;		// loopProgress serves a dual purpose. The decimal component represents the ball's progress through a loop e.g. 0.5 means it's halfway through		// The integer component represents the which loop the ball is on and removes the need for a loop counter		if ( ( this._endProgress - this._loopProgress) < 0.5 ) {			// This checks for when the loopProgress is within a halfturn from the end point			this._radiusIntermediary = this._settings.radiusEnd + ( (( this._endProgress - this._loopProgress ) / 0.5) * this._radiusDiff);			// At which point the radius decreases as the ball moves inwards.			if ( this._loopProgress >= this._endProgress ) {				// When the ball has moved past the end point it goes through the stopping process				this._stopBall();			} else {				this._setBallPosition( this._loopProgress % 1 );			}		} else {			this._setBallPosition( this._loopProgress % 1 );		}	}_setBallPosition( loopProgress ) {		// Taking a loopProgress value in the range [0-1] this function will set the ball to the position that corresponds to		switch ( this._getPhase( loopProgress ) ) {			case 0:				this._arcProgress = 2 * PI * (loopProgress / this._lengthPercentagesArcTotal);				this._point.x = RouletteWheel._getCircleX( this._arcProgress - (PI / 2), this._radiusIntermediary );				this._point.y = RouletteWheel._getCircleY( this._arcProgress - (PI / 2), this._radiusIntermediary );				break;			case 1:				this._lineProgress = (loopProgress - this._lengthPercentages[ 0 ]) / this._lengthPercentages[ 1 ];				this._point.x = -1 * this._lineProgress * this._settings.lengthLine;				this._point.y = this._radiusIntermediary;				break;			case 2:				this._arcProgress = 2 * PI * ((loopProgress - this._lengthPercentages[ 1 ]) / this._lengthPercentagesArcTotal);				this._point.x = RouletteWheel._getCircleX( this._arcProgress - (PI / 2), this._radiusIntermediary ) - this._settings.lengthLine;				this._point.y = RouletteWheel._getCircleY( this._arcProgress - (PI / 2), this._radiusIntermediary );				break;			case 3:				this._lineProgress = (loopProgress - this._lengthPercentagesArcTotal - this._lengthPercentages[ 1 ]) / this._lengthPercentages[ 3 ];				this._point.x = -1 * (1 - this._lineProgress) * this._settings.lengthLine;				this._point.y = -1 * this._radiusIntermediary;				break;			default :		}		this._point.y *= this._settings.motionStretchY;		this._ball.x = this._settings.offsetX + this._point.x;		this._ball.y = this._settings.offsetY + this._point.y;	}`

I cant see why this would sometimes stutter on a PC?

Thanks,

Dom

##### Share on other sites

Chrome has an open bug about a bad vsync problem with requestAnimationFrame, which Phaser uses under the hood. The frequent stutter could be that.

Without seeing the game running it's hard to tell. But... is there any way to pre-calc the ball rotation?