在Corona SDK中拖动时出现故障?

我在可拖动对象上遇到了问题。当我快速通过另一个对象拖动一个对象时,它会粘在其他对象中。然后当我释放它时,它会飞走。

以下是我使用gameUI.lua编写的代码。有人可以帮帮我吗?

display.setStatusBar(display.HiddenStatusBar)

local physics = require(“physics”)
physics.start()
physics.setDrawMode(“normal”)
physics.setGravity(0,5)

local gameUI = require(“gameUI”)

local floor = display.newImage(“floor.jpg”)
physics.addBody(floor,“static”,{摩擦=999,弹跳=0})
floor.y = 900

local box = display.newImage(“box.png”)
physics.addBody(box,{摩擦=99,弹跳=0})
box.x = 100

函数localDrag(事件)
    gameUI.dragBody(event,{maxForce=100000,frequency=1000,dampingRatio=1,center=true})
end

function box:touch(event)
if event.phase == “began” then

    self.markX = self.x
    self.markY = self.y

if event.phase == “moved” then

    local x =(event.x-event.xStart)+ self.markX
    local y =(event.y-event.yStart)+ self.markY

    self.x,self.y = x,y

    if(self.x> 595)则
     Self.x = 595
    end
    if(self.x <46),则
    self.x = 46
end
    if(self.y> 795)则
    self.y = 795
    end
end

return true
end

box:addEventListener(“touch”,localDrag)

local triangle = display.newImage(“triangle.png”)
三角形。x = 200
triangleShape = {-45,45,-45,-45,45,45}
physics.addBody(triangle,{摩擦=99,弹跳=0,形状=三角形})
函数localDrag(事件)
gameUI.dragBody(event,{maxForce=1000000,frequency=1000,dampingRatio=1,center=true})
end

function triangle:touch(event)
if event.phase == “began” then

    self.markX = self.x
    self.markY = self.y

elseif event.phase == “moved” then

    local x =(event.x-event.xStart)+ self.markX
    local y =(event.y-event.yStart)+ self.markY

    self.x,self.y = x,y

    if(self.x> 595)则
     Self.x = 595
    end
    if(self.x <46),则
    self.x = 46
end
    if(self.y> 795)则
    self.y = 795
end
end

return true
end
triangle:addEventListener(“touch”,localDrag)

local wall = display.newImage(“wall.jpg”)
physics.addBody(墙,“static”,{摩擦=0,弹跳=0})
墙.x = 665

local wall1 = display.newImage(“wall.jpg”)
physics.addBody(Wall1,“static”,{摩擦=0,弹跳=0})
wall1.x = -25
点赞
用户1508495
用户1508495

你的摩擦力很高,我建议你大幅度降低它。(在 Corona SDK 文件中,你可以了解关于身体属性的更多细节,这个我在这篇文章中无法涉及。)

至于你的物体被卡住,这可能与摩擦力有关,但如果它们实际上有任何重叠,我会怀疑那是因为睡眠状态。你可以在引起问题的物体上将 obj.isSleepingAllowed = false 设置为 on,测试一下,我相信你会看到明显的改善。

2012-07-12 14:30:03