トップページ > Sprite > beginFill()とlineStyle()を組み合わせる



概要

前回、lineStyle()を使用して輪郭部分を描くということを学びました。
今回はlineStyle()とbeginFill()を組み合わせてみようと思います。


プログラム

x = y = 232;
graphics.lineStyle(2.0);
 
graphics.beginFill(0xFF0000);
graphics.drawCircle(0, 0, 100);
graphics.endFill();
 
graphics.beginFill(0x00FF00);
graphics.drawRect(0, 0, 100, 100);
graphics.endFill();
 
赤と緑で描かれたオブジェクトに黒色の輪郭を描きます。

実行するとこのように表示されます。
色を引き締めたい時にlineStyle()で輪郭を描く、という使い方が出来ますね。


graphics.beginFill(0xFF0000);
graphics.moveTo(100, 100);
graphics.lineTo(150, 150);
graphics.lineTo(100, 200);
graphics.lineTo(100, 100);
graphics.endFill();
 

beginFill()で何かの色を設定している状態で、lineTo()で描かれた線のパスが閉じられるとその内部が塗りつぶされます。
(正確には、3点以上のポイントがあれば自動で補完され塗りが適用されるようです)


実行結果



検証用コード

package
{
	import flash.display.Sprite
 
	public class Main extends Sprite
	{
		public function Main():void
		{				
			x = y = 232;
			graphics.lineStyle(2.0);
 
			graphics.beginFill(0xED1A3D);
			graphics.drawCircle(0, 0, 100);
			graphics.endFill();
 
			graphics.beginFill(0x008000);
			graphics.drawRect(0, 0, 100, 100);
			graphics.endFill();
		}
	}
}
 

|新しいページ|検索|ページ一覧|RSS|@ウィキご利用ガイド | 管理者にお問合せ
|ログイン|
添付ファイル