我有這段代碼用於拖放遊戲。我該如何檢查動作3如果數組中的每個項目都有hitTestObject項目的第二個數組
如何檢查動作3如果數組中的每個項目都有hitTestObject第二個數組的項目,那麼可以發生其他情況,例如顯示完成的消息。
var hitArray:Array = new Array(hitTarget1,hitTarget2,hitTarget3,hitTarget4,hitTarget5);
var dropArray:Array = new Array(drop1,drop2,drop3,drop4,drop5);
var positionsArray:Array = new Array();
for (var i:int = 0; i < dropArray.length; i++) {
dropArray[i].buttonMode = true;
dropArray[i].addEventListener(MouseEvent.MOUSE_DOWN, mdown);
dropArray[i].addEventListener(MouseEvent.MOUSE_UP, mUp);
positionsArray.push({xPos:dropArray[i].x, yPos:dropArray[i].y});
}
function mdown(e:MouseEvent):void {
e.currentTarget.startDrag();
setChildIndex(MovieClip(e.currentTarget), numChildren - 1);
}
function mUp(e:MouseEvent):void {
var dropIndex:int = dropArray.indexOf(e.currentTarget);
var target:MovieClip = e.currentTarget as MovieClip;
target.stopDrag();
if (target.hitTestObject(hitArray[dropIndex])) {
target.x = hitArray[dropIndex].x;
target.y = hitArray[dropIndex].y;
playSound(sosto);
}else{
target.x = positionsArray[dropIndex].xPos;
target.y = positionsArray[dropIndex].yPos;
}
}
reset.addEventListener(MouseEvent.CLICK, backObjects);
function backObjects(e:MouseEvent):void{
for(var i:int = 0; i < dropArray.length; i++){
if(dropArray[i].x == hitArray[i].x && dropArray[i].y == hitArray[i].y){
dropArray[i].x = positionsArray[i].xPos;
dropArray[i].y = positionsArray[i].yPos;
}
}
}
function playSound(SoundName:Class):void{
var sound = new SoundName();
var channel:SoundChannel = sound.play();
}
playSound(sosto);
做一個循環,循環遍歷數組A,在每次迭代中hitTest B的每個元素。顯示消息時,點擊。打破循環。 –
我需要一些更多的幫助來了解如何在數組A中循環,hitTest B的每個元素在每次迭代中 – Marianna
http://stackoverflow.com/questions/24496848/as3-enemies-in-an-array-hit-testing-每個其他 –