Hi
I’m working on a game were I use for different buttons. For each of the I have set up a collision detection. As soon as it collides, then the collision changes the status of the button and turns of the collision detection for the button.
Here is the collision detection function
--COLLISION DETECTION local previousGrip local function collisionDetection(buttonParam) local buttonGrip = {} local closestX, closestY, distance, prevDist --SET GRIP TO ACTIVE if (previousGrip ~= nil) then buttonGrip[buttonParam] = previousGrip --print(buttonGrip[buttonParam]) --print(#buttonGrip) prevDist = findDistance(buttonParam.x, buttonParam.y, grip[previousGrip].x, grip[previousGrip].y) if (prevDist \> 30) then grip[previousGrip].status = "active" end end --EVENT COLLISION if (distance \< r) then previousGrip = i --stage:setFocus( body, nil ) --body.isFocus = false buttonParam.bodyType = "static" audio.play(touchSound, {loop = 0}) buttonParam.x = grip[i].x --+ (gripWidth/2) buttonParam.y = grip[i].y --+ (gripHeight/2) grip[i].status = "pasive" --body.tempJoint:removeSelf() end end end
This funtion is then being used in startDrag function in phase=move like collisionDetection(event.target). If I print(buttonParam) in the collisionDetection function, then I get a table. I’d like to asign the variable “i” to the currently selected button, so I can access it later on. I tryed to enter the values into a table with " buttonGrip[buttonParam] = previousGrip" but this didn’t work out or at least did not give the results I was hoping for.
My goal is to change the status only for the currently selected button. In a way it works fine, but only if I drag the same button as before. As soon as I choose another button, then this one snaps back to its origin only to work out on the second try. I’d like to eliminate the first try. 
Sorry if this post is a bit messy. Please help…