6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Align の実装

6
Posted at

こんなのを作っておく

Align.as
class Align
{
	public static const TOP_LEFT: Align		 = new Align(0);
	public static const TOP: Align			 = new Align(1);
	public static const TOP_RIGHT: Align	 = new Align(2);
	
	public static const LEFT: Align			 = new Align(3);
	public static const CENTER: Align		 = new Align(4);
	public static const RIGHT: Align		 = new Align(5);
	
	public static const BOTTOM_LEFT: Align	 = new Align(6);
	public static const BOTTOM: Align		 = new Align(7);
	public static const BOTTOM_RIGHT: Align	 = new Align(8);
	
	private var _value: int;
	
	public function Align(value: int) { _value = value % 9; }
	
	public function get value(): int { return _value; }
}

使う時はこんなん感じ

test.as
function layout(target: DisplayObject, align: Align, width: Number, height: Number): void
{
	var value: int = align.value;
	target.x = (width  - target.width)  / 2 * (value % 3);
	target.y = (height - target.height) / 2 * (value / 3 | 0);
}

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?