Notes: Positioning Optimizations

Tuesday, April 7th, 2009 | Notes

This page sort of expands upon the previous post I made on loop optimizations. I’m going to use this post in the future as a catchall for any other optimizations I run across. So for now I just have one to list, but hopefully in the future I’ll add some more.

Edit: (Sept 8th 2009) Ok I was kidding, I think I’m going to make separate posts each time. That way it shows up as a new post and people actually notice it. The “optimization” tag can be used to filter out just these posts.

Modifying a DisplayObject

Using a Matrix to modify a DisplayObject is faster than editing the individual properties.

	// 1 Million runs 2578ms, 2583ms, 2572ms
	spr.transform.matrix = new Matrix(spr.scaleX * 0.98, spr.scaleY * 0.98, 0, 0, spr.x + pt.x, spr.y + pt.y);
	

is faster than

	// 1 Million runs 3597ms, 3609ms, 3569ms
	spr.scaleX *= 0.98;
	spr.scaleY *= 0.98;
	spr.x += pt.x;
	spr.y += pt.y;
	

Tags:

1 Comment to Notes: Positioning Optimizations

JamesD
June 11, 2009

Thanks for the useful info. It’s so interesting

Leave a comment

Please upgrade your Flash Player To submit a comment, you must have Flash Player 9.0.0 or higher installed. I use a flash form here to help prevent spam.

Search

Categories