mardi 4 avril 2017

Snapping multiple objects to multiple locations using Arrays

Having trouble making a simple game that involves covering a grid with colored tiles. I have used Arrays to establish drag and drop functionality but cannot find a way to easily have them snap to the locations on the grid. I have made the locations on the grid into movie clips with names snapA1 through snapJ10, all in groups of 10 by letters and with instance names to match, but those clips have been removed from Arrays as they don't need to move. The problems I keep having is that any function I use only works to allow snapping to single locations. Basically I'm just looking for a short hand to allow two or more groups of objects to snap onto each other, preferably without having to brute-force code, I kid you not, 20,000 instances of the same code. below is the code I have that so far only allows one snapping target location


var greenArr:Array = new Array 
(greenTablet1, greenTablet2, greenTablet3, greenTablet4, greenTablet5,
greenTablet6, greenTablet7, greenTablet8, greenTablet9, greenTablet10,
greenTablet11, greenTablet12, greenTablet13, greenTablet14, greenTablet15, 
greenTablet16, greenTablet17, greenTablet18, greenTablet19, greenTablet20);

for (var i1:uint =0; i1 < greenArr.length; i1++) {
 greenArr[i1].addEventListener(MouseEvent.MOUSE_DOWN, dragG);
 greenArr[i1].addEventListener(MouseEvent.MOUSE_UP, dropG);

function dragG(event:MouseEvent):void {

function dropG(event:MouseEvent):void {

stage.addEventListener(MouseEvent.MOUSE_UP, stopMotionG1);

function stopMotionG1(evt:MouseEvent):void {
function snapInPlaceG1():void {
if (snapA1.hitTestObject(greenTablet1)) {
greenTablet1.x = snapA1.x;
greenTablet1.y = snapA1.y;


Aucun commentaire:

Enregistrer un commentaire