我有一个游戏,允许用户创建自己的图片。他们可以从我创建的菜单中选择不同的元素。当他们单击一个元素时,会创建一个实例,他们可以拖动到上面的工作区域。他们正在创建的图片呈圆形,因此,如果用户拖动圆圈边缘附近的元素,它应该被切断。 *(想象一个矩形图像,中间有一个透明圆圈,你可以看到所有元素通过)
目前,我可以将一个元素拖到工作区域,它只会显示在圆圈内(如果它在圆圈外面则会被剪切掉),但是一旦拖动它,我就无法点击并拖动它再次,因为它是在图像下。
如何让矩形图像显示在所有元素的顶部,同时仍允许用户点击并拖动已放置的元素?
(我制作了一个图表,以便更容易理解,但我没有足够的代表点发布它)
var sb1:sbMenu1 = new sbMenu1();
var sb2:sbMenu2 = new sbMenu2();
var sb3:sbMenu3 = new sbMenu3();
var sb4:sbMenu4 = new sbMenu4();
backgrounds.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_5);
function fl_MouseClickHandler_5(event:MouseEvent):void
{
this.addChild(sb1);
sb1.visible = true;
sb2.visible = false;
sb3.visible = false;
sb4.visible = false;
sb1.x = 0
sb1.y = 550
}
nature.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_4);
function fl_MouseClickHandler_4(event:MouseEvent):void
{
this.addChild(sb2);
sb2.visible = true;
sb1.visible = false;
sb3.visible = false;
sb4.visible = false;
sb2.x = 0
sb2.y = 550
}
animals.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_6);
function fl_MouseClickHandler_6(event:MouseEvent):void
{
this.addChild(sb3);
sb3.visible = true;
sb1.visible = false;
sb2.visible = false;
sb4.visible = false;
sb3.x = 0
sb3.y = 550
}
objects.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_7);
function fl_MouseClickHandler_7(event:MouseEvent):void
{
this.addChild(sb4);
sb4.visible = true;
sb1.visible = false;
sb2.visible = false;
sb3.visible = false;
sb4.x = 0
sb4.y = 550
}
thesubmenu1.hill.addEventListener(MouseEvent.MOUSE_DOWN, createCopy);
var i:int=0;
var tmpImage:Sprite; //to store which image is being dragged currently
function createCopy(e:MouseEvent):void {
tmpImage = new Hill_mc();
tmpImage.name = "hillChild"+(i++); //increment every copy
addChild(tmpImage);
tmpImage.x = mouseX;
tmpImage.y = mouseY;
tmpImage.startDrag();
tmpImage.buttonMode = true;
tmpImage.addEventListener(MouseEvent.MOUSE_DOWN, onDown); //add the mouse down to this new object
stage.addEventListener(MouseEvent.MOUSE_UP, onUp); //since the mouse is currently down, we need to listen for mouse up to tell the current copy to stop dragging
}
//this will be called when click a copy
function onDown(e:MouseEvent):void {
tmpImage = Sprite(e.currentTarget); //get a reference to the one that was clicked, so we know which object to stop dragging on the global mouse up.
stage.addEventListener(MouseEvent.MOUSE_UP, onUp); //listen for the mouse up
tmpImage.startDrag();
}
function onUp(e:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_UP,onUp);
if (tmpImage.hitTestObject(thesubmenu1)) {
removeChild(tmpImage);
}
else {
tmpImage.stopDrag();
}
}
thesubmenu1.foreground.addEventListener(MouseEvent.MOUSE_DOWN, createCopy2);
function createCopy2(e:MouseEvent):void {
tmpImage = new Foreground_mc();
tmpImage.name = "foregroundChild"+(i++); //increment every copy
addChild(tmpImage);
tmpImage.x = mouseX;
tmpImage.y = mouseY;
tmpImage.startDrag();
tmpImage.buttonMode = true;
tmpImage.addEventListener(MouseEvent.MOUSE_DOWN, onDown); //add the mouse down to this new object
stage.addEventListener(MouseEvent.MOUSE_UP, onUp); //since the mouse is currently down, we need to listen for mouse up to tell the current copy to stop dragging
}
stage.addChild(seal);