dポイントプレゼントキャンペーン実施中!

現在hitTestopoint()を使った移動範囲の制限について調べています。
以下のスクリプトにおいて、イラストレーターで作った描画(B)を、円形のオブジェクトms(A,右方向に進んでいく)の移動の制限範囲と使いたいのですが、まず(1)のようになスクリプトを作成すると、正確な描画の範囲ではなく、大まかな範囲(大きな四角)の端で制限が適応されます。(動きが止まります。)この描画はaiデータをライブラリーに読み込んだものをそのままステージに置いただけなので、bitmapにしたらどうなるかと思い、(2)を記述しましたが、こちらも結果は同じでした。どのように考えたらよろしいのでしょうか?お心当たりございましたら、是非お願い致します。
補助画像を添付しております。

*(2)では描画テータにhit3というクラスでリンケージしてます。


(1)

import flash.display.Sprite;
import flash.events.Event;

var ms:Sprite = new Sprite();
ms.graphics.beginFill(0x552277);
ms.graphics.drawCircle(30,30,60);
ms.graphics.endFill();

addChild(ms);

this.addEventListener(Event.ENTER_FRAME,go)
function go(event:Event):void{

ms.x += 5

if (! hito4.hitTestPoint(ms.getBounds(this).right,ms.y, true)) {
ms.x -= 5;
}
if (! hito4.hitTestPoint(ms.getBounds(this).left, ms.y, true)) {
ms.x += 5;
}
if (! hito4.hitTestPoint(ms.x, ms.getBounds(this).bottom, true)) {
ms.y -= 5;
}
if (! hito4.hitTestPoint(ms.x,ms.getBounds(this).top, true)) {
ms.y += 5;
}

}

(2)

import flash.display.Sprite;
import flash.events.Event;
import flash.display.BitmapData;
import flash.display.Bitmap;

var hito_bmp:BitmapData= new hito3(0,0);
var hito_bmp_on:Bitmap= new Bitmap(hito_bmp,PixelSnapping.AUTO,true);
stage.addChild(hito_bmp_on);
hito_bmp_on.x=-150
hito_bmp_on.y=-100

var ms:Sprite = new Sprite();
ms.graphics.beginFill(0x552277);
ms.graphics.drawCircle(30,30,60);
ms.graphics.endFill();

addChild(ms);

this.addEventListener(Event.ENTER_FRAME,go)
function go(event:Event):void{

ms.x += 5

if (!hito_bmp_on.hitTestPoint(ms.getBounds(this).right,ms.y, true)) {
ms.x -= 5;
}
if (!hito_bmp_on.hitTestPoint(ms.getBounds(this).left, ms.y, true)) {
ms.x += 5;
}
if (!hito_bmp_on.hitTestPoint(ms.x, ms.getBounds(this).bottom, true)) {
ms.y -= 5;
}
if (! hito_bmp_on.hitTestPoint(ms.x,ms.getBounds(this).top, true)) {
ms.y += 5;
}

}

「actionscript3.0,hitT」の質問画像

A 回答 (1件)

まず大前提として、hitTestPointはシェイプにしか反応できません。


それ以外のものは表示オブジェクトの矩形で判定されます。
ビットマップも同じです。(アルファ透過している部分も画像なのです)

Illustratorから読み込んで作ったシンボルの中身がシェイプでできている、
即ちシンボル(グラフィック・ムービークリップ)やグループ、
描画オブジェクトが含まれていないことをまず確認してみてください。
    • good
    • 0
この回答へのお礼

ご推察のとおりbitmapとしてと読込んでいました。
データ読み込み仕方を変更したところ、できるようになりました。
ありがとうございました。

お礼日時:2012/03/08 07:29

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!