Thursday, July 24, 2008
AE / pointInPoly
pointInPoly(移動するオブジェクトのロケーション, 多角形のポイントリスト)
pointInPoly(the loc of grc "pipBut", the points of grc "pipPoly")
多角形(poligon) の不透明部分に、他のオブジェクトのロケーション(センター部分)が入った時に、true を返します。
ポリゴンの名前「pipPoly」、円の名前「"pipBut」にしてメッセージボックスから
set the constrainRectangular of grc "pipPoly" to the rect of this card
set the constrainRectangular of grc "pipBut" to the rect of this card
constrainRectangular は、オブジェクトが移動できる範囲を設定して、オブジェクト内の on mouseMove に grab me が書かれているのと、同じような働きをします。 constrainRectangular が設定してあれば、オブジェクト内に grab me は必要ありません。
-- カード内に入れるスクリプト。 true になった時に色を変える
on constrainRectangularCallback
if pointInPoly(the loc of grc "pipBut", the points of grc "pipPoly") then
set the backgroundColor of grc "pipBut" to blue
set the backgroundColor of grc "pipPoly" to green
else
set the backgroundColor of grc "pipBut" to green
set the backgroundColor of grc "pipPoly" to blue
end if
end constrainRectangularCallback
始めにAnimation Engineを開いて、start using stack "animationEngine"
サンプルスタックは、下記をメッセージボックスにコピペしてリターンキーを
go stack url "http://homepage.mac.com/kenjikojima/jrevnote/pointInPoly.rev"
false
true