I Need help to set drag to become turn off when I hit start, and when I hit pause the drag becomes draggable
Likes here the code for it
function new()
local localGroup = display.newGroup()
local physics = require(“physics”)
require "ui"
physics.start()
–Drag function
local function startDrag( event )
local t = event.target
local phase = event.phase
if “moveable” == true then
if “began” == phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true
– Store initial position
t.x0 = event.x - t.x
t.y0 = event.y - t.y
– Make body type temporarily “kinematic” (to avoid gravitional forces)
event.target.bodyType = “kinematic”
elseif t.isFocus then
if “moved” == phase then
t.x = event.x - t.x0
t.y = event.y - t.y0
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
– Switch body type back to “dynamic”, unless we’ve marked this sprite as a platform
if ( not event.target.isPlatform ) then
event.target.bodyType = “static”
end
end
end
end
– Stop further propagation of touch event!
return true
end
local gameUI = require(“gameUI”)
local dragBody = gameUI.dragBody
–This represents platform
local wall2 = display.newRect(50, 100, 20, 100)
physics.addBody(wall2, “static”, {friction = 0.7})
wall2.isPlatform = true
wall2:setFillColor(0, 0, 0)
wall2.rotation = 90
wall2:addEventListener( “touch”, startDrag )
local function rotate (event)
wall2.rotation = wall2.rotation +10
end
wall2:addEventListener(“tap”, rotate)
–Platform2
local wall3 = display.newRect(100, 200, 20, 100)
physics.addBody(wall3, “static”, {friction = 0.7})
wall3.isPlatform = true
wall3:setFillColor(0, 0, 0)
wall3.rotation = 90
wall3:addEventListener( “touch”, startDrag )
local function rotate (event)
wall3.rotation = wall3.rotation +10
end
wall3:addEventListener(“tap”, rotate)
–Start button
local bt = display.newImage (“pause.png”)
bt.x = 290
bt.y = 30
–Pause Button
local bt2 = display.newImage (“pauseover.png”)
bt2.x = bt.x
bt2.y = bt.y
-Function for start button
local function done ()
if “ended” == phase then
if “moveable” == false then
physics.start()
physics.addBody(ball, { bounce = 0.3, radius = (ball.contentHeight /1.7) - 2})
bt.isVisible = false
bt2.isVisible = true
end
end
end
bt:addEventListener(“tap”, done)
–Function for pause button
local function done ()
physics.pause()
bt.isVisible = true>
bt2.isVisible = false>
ball.x = 160
ball.y = 30
bt2.isVisible = false
end
bt2:addEventListener(“tap”, done)
What I’m trying to do for the start button function is have the platform become undraggable when start function is started, and when pause button function is tap the platform becomes draggable again.
[import]uid: 17058 topic_id: 18944 reply_id: 318944[/import]