私は自分のドラッグ機能を転がすのを避けようとしています。startDrag()
たとえば、長方形のボックスではなく、ドラッグ境界に円形の半径を使用できる同等のものがあるライブラリを知っている人はいますか?
4 に答える
(円形のドラッグ領域の場合) - あなたがする必要があるのは:
a) Mouse_down: 開始位置を保存します。Enter_frame の再生を開始します。
b) Enter_Frame: マウスのマウス位置から開始位置までの距離を確認します (ピタゴラスを使用)
c) 距離が x 未満の場合にのみ、オブジェクトを移動します
d) Mouse_up: enterframe のリッスンを停止
簡単な円形の衝突検出ルーチンを使用できます。オブジェクトの半径とオブジェクト間の距離を使用してヒット領域を計算します。おそらく、onDrag メソッドでこの計算を手動で行い、以下で計算された円形の境界でドラッグ オン コリジョンを停止する必要があります。
var deltax : Number = targetCentreCoord.x - hitTestCentreCoord.x;
var deltay : Number = targetCentreCoord.y - hitTestCentreCoord.y;
//works out if our circles are colliding, distance between the circles inc radius
if (((deltax * deltax) + (deltay * deltay)) <= ((((targetRadius) + (hitTargetRadius)) * ((targetRadius) + (hitTargetRadius)))))
{
Log.info("collision occured with " + candidate.name + " target coords " + targetCentreCoord + " candidate coords " + hitTestCentreCoord);
return true;
}
return false;
いいえ、それを行うには、ピクセル単位で完全な衝突 (この場合はマウス クリック) を行う必要があります。本来、すべての表示オブジェクトには常に長方形の境界があります。したがって、基本的には次のようにする必要があります。
mySprite.addEventListener(MouseEvent.MOUSE_DOWN, mousedDown);
function mousedDown(e:MouseEvent):void
{
//Draw my sprite to a bitmap, then check the bitmap colour at mouseX/mouseY
uint colour = myBitmap.getPixel32(mouseX, mouseY);
if(colour != TRANSPARENT){
//We've actually clicked on the object, drag it
Sprite(e.currentTarget).startDrag();
}
}
これは単なる疑似コードであることに注意してください。どの uint 値が透明になるかを把握する必要があります。また、ビットマップに描画するときにスプライトの原点がどこにあるかを考慮する必要があります。スプライトがあり、コンテンツが内部にあるとします。適切に描画するには、スプライトの幅の負の 0.5 倍の X オフセットと Y オフセットを持つ Matrix オブジェクトを作成する必要があります。