actionscript 3 - Add a movieclip but make sure it isn't in the same place as another movieclip. (as3) -
so have this add movieclips clicking, unefficient , doesn't have functionality want, need add movieclip if no other movieclip in same place.
private function onclick():void { if(placesound==false) { placepixel.play(); placesound = true; } if(erasetrue==false) { var pixel = new pixel(); pixel.x = 0; pixel.y = 0; } if(mousey>30 && irontrue==true) { //var pixel = new pixel(); pixel.x=(math.round(mousex/5)*5)-2.5; pixel.y=(math.round(mousey/5)*5)-2.5; pixel.graphics.beginfill(0x999999); pixel.graphics.drawrect(0, 0, 5, 5); pixel.graphics.endfill(); pixel.type=0; pix.push(pixel); //addchild(pixel); } if(mousey>30 && woodtrue==true) { //var pixel = new pixel(); pixel.x=(math.round(mousex/5)*5)-2.5; pixel.y=(math.round(mousey/5)*5)-2.5; pixel.graphics.beginfill(0x996600); pixel.graphics.drawrect(0, 0, 5, 5); pixel.graphics.endfill(); pixel.type=3; pix.push(pixel); //addchild(pixel); } if(erasetrue==true) { (i=pix.length-1; i>=0; i--) { if(pix[i].x==(math.round(mousex/5)*5)-2.5 && pix[i].y==(math.round(mousey/5)*5)-2.5) { removechild(pix[i]); pix.splice(i, 1); } } } if(mousey>30 && springtrue==true) { //var pixel = new pixel(); pixel.x=(math.round(mousex/5)*5)-2.5; pixel.y=(math.round(mousey/5)*5)-2.5; pixel.graphics.beginfill(0x000000); pixel.graphics.drawrect(0, 0, 5, 5); pixel.graphics.endfill(); pixel.type=1; pix.push(pixel); //addchild(pixel); } if(mousey>30 && portaltrue==true) { //var pixel = new pixel(); pixel.x=(math.round(mousex/5)*5)-2.5; pixel.y=(math.round(mousey/5)*5)-2.5; pixel.graphics.beginfill(0x9999ff); pixel.graphics.drawrect(0, 0, 5, 5); pixel.graphics.endfill(); pixel.type=2; pix.push(pixel); //addchild(pixel); } if(erasetrue==false) { addchild(pixel); } }
i want somehow run last if (the 1 addchilds pixel.) if no other movieclip (see array "pix") has in spot placed in. (i round mouse before placing it.
thanks help.
edit: spoilers failed.
loop through pix array see if of pixels in array match x , y coordinates of new pixel object. if not, pixel should added.
so instead of final if statement:
... if(erasetrue==false){ var canplace:boolean = true; (var i:int = 0; < pix.length; i++){ var placedpixel:pixel = pix[i] pixel; if(pixel.x == placedpixel.x && pixel.y == placedpixel.y){ canplace = false; } } if(canplace){ addchild(pixel); } }
Comments
Post a Comment