我嘗試在我的場景中拖動一個動態的物體與重力= 0,0,我有一個正方形與體型動態,和一個圖像與體型靜態,但是當拖動廣場到這個圖片的有一點點力,但可以超過圖像,並傳送給對方喜歡的圖片:在電暈sdk中拖動物理對象
這是我的代碼拖動方:
local function dragBody(event)
local body = event.target
local phase = event.phase
local stage = display.getCurrentStage()
if "began" == phase then
stage:setFocus(body, event.id)
body.isFocus = true
body.tempJoint = physics.newJoint("touch", body, event.x, event.y)
elseif body.isFocus then
if "moved" == phase then
body.tempJoint:setTarget(event.x, event.y)
elseif "ended" == phase or "cancelled" == phase then
stage:setFocus(body, nil)
body.isFocus = false
body.tempJoint:removeSelf()
end
end
return true
end
這是創建對象的代碼:
function scene:createScene(event)
local group = self.view
my_square = display.newImage("square.png")
my_square.x = 60
my_square.y = 60
physics.addBody(my_square, "dynamic")
group:insert(my_square)
floor = display.newImage("piso.png")
floor.x = 160
floor.y = 240
physics.addBody(floor, "static")
group:insert(floor)
end
感謝您的幫助。
感謝您的回覆,我正在用物理移動廣場,現在我將使用更多的對象,並且不會聽到所有對象的碰撞只是爲了移動 –