hitTestPointメソッドを使ってオブジェクトが指定したx位置、y位置にあるかどうか判定します。
hitTestPointメソッドの構成は
hitTestPoint(x:Number, y:Number, shapeFlag:Boolean = false):
となっています。
第一引数にはx値、第二引数にはy値、第三引数はshapeFlagです。
第三引数は代入しなくても判定可能です。自分は第三引数の代入は殆ど使ってません。
x値とy値はオブジェクトの表示コンテナではなくステージサイズを基準にしています。
例題
sample_mcというMCがhitTestPointで指定した値にヒットしているかどうか判定します。
sample_mcのx値は0、width値は100です。
hitTestPoint(100,0)にした時はtrue、hitTestPoint(100,0)にした時はfalseを返します。
ソースコード
var sample_mc:Sprite=new Sprite();
sample_mc.graphics.beginFill(0x000000);
sample_mc.graphics.drawRect(0,0,100,100)
sample_mc.graphics.endFill();
addChild(sample_mc)
trace("sample_mcがhitTestPointで指定した範囲にヒットしているかどうか判定 = "+sample_mc.hitTestPoint(100,0))//output true
trace("sample_mcがhitTestPointで指定した範囲にヒットしているかどうか判定 = "+sample_mc.hitTestPoint(101,0))//output false
|