我正在开发迷宫游戏但不明白我怎么能用.png创建绘制线的碰撞。 我的迷宫本身是一个.png文件,其中waypaths用透明部分表示。不透明部分代表迷宫的墙壁。玩家的目标是在透明部分画线,不要撞墙。
我的绘制线也包含BitmapDataStyle。这是代码:
import flash.events.*;
import flash.display.*;
stage.addEventListener(Event.ENTER_FRAME, f_enterFrameHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, f_mouseUp);
stage.addEventListener(MouseEvent.MOUSE_DOWN, f_mouseDown);
var m = new MovieClip();
var w = stage.addChild(m);
var g = m.graphics;
var misdown = false;
var bitmap:BitmapData = new mark_line;
g.lineStyle(6,0x444444,1);
g.lineBitmapStyle(bitmap);
g.moveTo(0,0);
function f_enterFrameHandler(e:Event)
{
if (misdown)
f_drawLine();
}
function f_mouseUp(e:MouseEvent)
{
misdown = false;
}
function f_mouseDown(e:MouseEvent)
{
misdown = true;
g.moveTo(w.mouseX,w.mouseY);
}
function f_drawLine()
{
g.lineTo(w.mouseX,w.mouseY);
}
答案 0 :(得分:0)
你必须检测两个形状的命中,你必须使用bitmapData.hitTest()。您可以从其bitmapData中检测任何形状之间的碰撞。要做到这一点,你必须在bitmapData上绘制两个形状,如line belo:
var shape1Bitmap:BitmapData = new BitmapData(shape1MC.with,shape1MC.height,true,0x000000);
shape1Bitmap.draw(shape1MC);
var shape2Bitmap:BitmapData = new BitmapData(shape1MC.with,shape1MC.height,true,0x000000);
shape1Bitmap.draw(shape1MC);
shape1Bitmap.hitTest(new Point(),shape2Bitmap):Boolean;
继续使用BitmapData.hitTest(),按照此处的命令进行操作:https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#hitTest()
http://dougmccune.com/blog/2007/02/03/using-hittestpoint-or-hittest-on-transparent-png-images/
祝你好运