I’m new to Corona and I was trying to make an image on the screen to be draggable no matter where you touch the screen (you don’t necessarily need to touch this image inside)
One way is to have a full screen box set to alpha=.01 that is the actual draggable object and then make the image follow that object as you drag it. That way you dont have to tap and drag on the actual object.
Do you want the image to “snap” to your finger location? That too is possible.
[import]uid: 7845 topic_id: 10147 reply_id: 37028[/import]
Thank you for your reply, but I can’t figure it out how to make it work.
I have this code:
local physics = require("physics")
physics.start()
local function startDrag( event )
local t = event.target
local phase = event.phase
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"
-- Stop current motion, if any
event.target:setLinearVelocity( 0, 0 )
event.target.angularVelocity = 0
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 = "dynamic"
end
end
end
-- Stop further propagation of touch event!
return true
end
local ball = display.newImage( "images/ball.png" )
ball.x = 40; ball.y = 280
physics.addBody( ball, "kinematic", { friction=0.7 } )
ball.isPlatform = true -- custom flag, used in drag function above
ball:addEventListener( "touch", startDrag )
but I want to touch around the ball and be draggable not on it’s surface only. how should I alter this? [import]uid: 8241 topic_id: 10147 reply_id: 37122[/import]
assuming your object “obj” is already created you could do something like this. Obviously, you will need to handle physics seperately if it’s physics object
****EDIT**** see my next post… [import]uid: 48521 topic_id: 10147 reply_id: 37091[/import]
I’m looking for someone to show me a couple of things in Corona, are you available(I will pay you, of course)? [import]uid: 8241 topic_id: 10147 reply_id: 37338[/import]