Actionscript 3 如何通过actionscript 3检查数组中的每个项是否都有第二个数组中的hitTestObject项
我有一个拖放游戏的代码 如何通过actionscript 3检查数组的每个项是否都有hitTestObject第二个数组的项,以便发生其他事情,例如显示一条完成良好的消息Actionscript 3 如何通过actionscript 3检查数组中的每个项是否都有第二个数组中的hitTestObject项,actionscript-3,Actionscript 3,我有一个拖放游戏的代码 如何通过actionscript 3检查数组的每个项是否都有hitTestObject第二个数组的项,以便发生其他事情,例如显示一条完成良好的消息 var hitArray:Array = new Array(hitTarget1,hitTarget2,hitTarget3,hitTarget4,hitTarget5); var dropArray:Array = new Array(drop1,drop2,drop3,drop4,drop5); var position
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);
var-hitArray:Array=新阵列(hitTarget1、hitTarget2、hitTarget3、hitTarget4、hitTarget5);
var dropArray:Array=新数组(drop1、drop2、drop3、drop4、drop5);
变量位置数组:数组=新数组();
for(变量i:int=0;i
尝试添加此行:
stage.addEventListener(Event.ENTER_FRAME, loop);
其中“loop”是一个包含其余代码的函数,看起来像
function loop (e:Event):void
{
//Your Code
}
祝你好运 让我们创建一个函数,告诉我们是否每个“命中目标”及其对应的“下降”都相互接触
function allCorrect():Boolean {
//for each item in the hitArray, we repeat the action
//we assume that length of hitArray and dropArray are the same
for (var i=0;i<hitArray.length;i++) {
//if the corresponding target and drop do not hit each other, return false
if (!(hitArray[i].hitTestObject(dropArray[i])) {
return false
//if we return false, this function will continue no further
}
}
//We have cycled through all of the items in the arrays, and none of the
//hitTestObjects have been false, so we return true
return true
}
希望这能回答你的问题 做一个循环,循环数组a,在每次迭代中测试B的每个元素。点击时显示消息。我需要更多的帮助来理解如何循环数组A,在每次迭代中测试B的每个元素
if (allCorrect()) {
//display "youz a cool cat, bro"
//remove all of your event listeners to improve performance
}