Hey guys I am new in developing apps could really use some help.
i have this code that helps me drag and snap.
when i drag it works perfectly fine how ever when i tap it automatically sends it to the snap position.
It is a music app i have a keyboard with seven buttons therefore have the same code 7 times for each button.
only one of the notes is supposed to snap which it does how ever when i tap all tend to snap.
could some one help me figure this out?
is there a way that the same code can apply to all buttons rather than have it 7 times?
(code)
-THIS IS THE B DRAG BUTTON
--Circle outline
Bline = display.newImageRect(sceneGroup, “images/B.png”, 100, 100);
Bline.x = display.contentCenterX
Bline.y = display.contentCenterY-42
Bline.alpha=0.01
– circle positioning
Bgoodbutton = display.newImageRect(sceneGroup, “images/B.png”, 100, 100);
Bgoodbutton.x = display.contentCenterX+151
Bgoodbutton.y = display.contentHeight-20
Bgoodbutton.alpha=0.01
Bgoodbutton:scale(.3, .3)
– Circle
MultiTouch.activate(Bgoodbutton, “move”, “single”);
– Set initial variables to 0
local BgoodbuttonPosX = 0;
local BgoodbuttonPosY = 0;
local function circleDrag (event)
local t = event.target
Bgoodbutton.alpha = 1
transition.to(Bgoodbutton, {time=210, xScale = .6, yScale = .8})
–If user touches & drags circle, follow the user’s touch
if event.phase == “moved” then
BgoodbuttonPosX = Bgoodbutton.x - Bline.x;
BgoodbuttonPosY = Bgoodbutton.y - Bline.y;
if (BgoodbuttonPosX < 0) then
BgoodbuttonPosX = BgoodbuttonPosX * -1;
end
if (BgoodbuttonPosY < 0) then
BgoodbuttonPosY = BgoodbuttonPosY * -1;
end
– If user drags circle within 50 pixels of center of outline, snap into middle
if (BgoodbuttonPosX <= 25) and (BgoodbuttonPosY <= 25) then
Bgoodbutton.x = Bline.x;
Bgoodbutton.y = Bline.y;
end
– When the stops dragging circle within 50 pixels of center of outline, snap into middle, and…
elseif event.phase == “ended” then
if (BgoodbuttonPosX <= 0.1) and (BgoodbuttonPosY <= 0.1) then
Bgoodbutton.x = Bline.x;
Bgoodbutton.y = Bline.y;
– …lock circle into place where it cannot be moved.
MultiTouch.deactivate(Bgoodbutton);
elseif (BgoodbuttonPosX >= 0.1) and (BgoodbuttonPosY >= 0.1) then
–Agoodbutton.x = Abutton.x;
–Agoodbutton.y = Abutton.y;
transition.to(Bgoodbutton, {time=500, x=display.contentCenterX+151, y=display.contentHeight-20, alpha=0.01, xScale = .3, yScale = .3})
– …lock circle into place where it cannot be moved.
else
print(“no hagas nada”)
end
end
return true;
end
Bgoodbutton:addEventListener(MultiTouch.MULTITOUCH_EVENT, circleDrag);
(/code)
thank you for your help