Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Estou com um problema que tudo o que eu tenho não está servindo, tudo é modificado no processo e eu estou ficando com muitas dúvidas na montagem do código, onde eu chamo determinada função, como eu reinicio e reposiciono movieclips com array.
1 - Eu tenho um jogo de arrastar que eu fiquei tentando adaptar sem sucesso, o que eu preciso?
Que a pessoa arraste mais de uma opção para o mesmo lugar.
Quantidade limitada, só posso arrastar 2 movieclips para o mesmo alvo.
Nesse código eu tentei alterar as posições com array, mas me perdi na lógica. No final os objetos deveriam voltar para posições diferentes.
var hitArray:Array = new Array(hitTarget1,hitTarget2,hitTarget3,hitTarget4);
var dropArray:Array = new Array(drop1,drop2,drop3,drop4);
var positionsArray:Array = new Array();
//This adds the mouse down and up listener to the drop instances
//and add the starting x and y positions of the drop instances
//into the 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});
}
//This drags the object that has been selected and moves it
//to the top of the display list. This means you can't drag
//this object underneath anything.
function mdown(e:MouseEvent):void {
e.currentTarget.startDrag();
setChildIndex(MovieClip(e.currentTarget), numChildren - 1);
}
//This stops the dragging of the selected object when the mouse is
//released. If the object is dropped on the corresponding target
//then it get set to the x and y position of the target. Otherwise
//it returns to the original position.
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;target.x = positionsArray[dropIndex].xPos;
target.y = positionsArray[dropIndex].yPos;
}
}var linha2:Sprite = new Sprite();
var posX:Number = 0;
var posY:Number = 0;
stage.addEventListener(MouseEvent.MOUSE_DOWN, desenha);
function desenha(e:MouseEvent):void
{
linha2.graphics.clear();
linha2.graphics.lineStyle(10,0x000000);
linha2.graphics.moveTo(posX,posY);
linha2.graphics.lineTo(mouseX,mouseY);
linha2.graphics.moveTo(posX,posY);
linha2.graphics.lineTo(posX+0,posY);
this.addChild(linha2);
}Carregando comentários...