衝突検出に BitmapData を使用しようとしてきましたが、これまでのところ失敗しており、理由がわかりません。コードはコンパイルされますが、何も実行されません ( "hit" が出力されるはずの場合)。誰でも私を助けることができますか?
package
{
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.display.MovieClip;
import flash.ui.Keyboard;
import flash.display.BitmapData;
import flash.geom.Point;
public class Main extends MovieClip
{
private var spd:int = 5;
private var pressedKeys:Object = {};
private var bgMask:BitmapData;
private var plMask:BitmapData;
private var wall:Wall = new Wall();
public function Main()
{
var bgBitMapData:BitmapData = new BitmapData(bg.width,bg.height,true,0);
bgMask = bgBitMapData.clone();
wall.x = bg.x;
wall.y = bg.y;
bgMask.draw( wall );
var plBitMapData:BitmapData = new BitmapData(pl.width,bg.height,true,0);
plMask = bgBitMapData.clone();
bgMask.draw( pl );
stage.addEventListener(KeyboardEvent.KEY_DOWN,this.keyPressHandler);
stage.addEventListener(KeyboardEvent.KEY_UP,this.keyPressHandler);
stage.addEventListener(Event.ENTER_FRAME,this.gameLoop);
}
public function keyPressHandler( evt:KeyboardEvent ):void
{
if (evt.type == KeyboardEvent.KEY_DOWN)
{
pressedKeys[evt.keyCode] = 1;
}
else
{
delete pressedKeys[ evt.keyCode ];
}
}
public function inputHandler():void
{
var moveXBy:int;
var moveYBy:int;
if (pressedKeys[Keyboard.J])
{
moveXBy -= spd;
}
if (pressedKeys[Keyboard.K])
{
moveYBy += spd;
}
if (pressedKeys[Keyboard.L])
{
moveXBy += spd;
}
if (pressedKeys[Keyboard.I])
{
moveYBy -= spd;
}
pl.x += moveXBy;
pl.y += moveYBy;
}
public function playerWallCollision():void
{
if ( plMask.hitTest( new Point( wall.x, wall.y ), 1, bgMask, new Point( pl.x, pl.y ), 1))
{
trace( "hit" );
}
}
public function gameLoop( evt:Event ):void
{
wallUpdate();
inputHandler();
playerWallCollision();
}
private function wallUpdate()
{
wall.x = bg.x;
wall.y = bg.y;
}
}
}