我想在同一点生成两个物理对象,然后通过施加力来移动一个物理对象,但是当一个对象移动时,它会与另一个物理对象发生碰撞。我不能将另一个对象设为非物理对象,因为这些对象会进一步相互碰撞,但最初它们不能碰撞。我所做的一些编码部分如下......请提出任何想法..谢谢
local obj2
local physicsbody1= { density=0.1, friction=0, bounce=0 }
local physicsbody2= {density=10.0, friction=0, bounce=0.1, radius=25 }
local function createobj2(_xpos,y_pos,_id)
obj2=display.newImage("obj2.png")
obj2.x=_xpos
obj2.y=_ypos
physics.addBody(obj2,physicsbody1)
end
local physicsObjStatic=display.newImage("img1.png")
physicsObjStatic.x=450
physicsObjStatic.y=200
physics.addBody(physicsObjStatic,physicsbody2)
local function Shot( event )
local t = event.target
local phase = event.phase
if "began" == phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true
t:setLinearVelocity( 0, 0 )
t.angularVelocity = 0
target.x = t.x
target.y = t.y
startRotation = function()
target.rotation = target.rotation + 4
end
Runtime:addEventListener( "enterFrame", startRotation )
local showTarget = transition.to( target, { alpha=0.4, xScale=0.4, yScale=0.4, time=200 } )
myLine = nil
elseif t.isFocus then
if "moved" == phase then
if ( myLine ) then
myLine.parent:remove( myLine )
end
myLine = display.newLine( t.x,t.y, event.x,event.y )
myLine:setColor( 255, 255, 255, 50 )
myLine.width = 8
elseif "ended" == phase or "cancelled" == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
local stopRotation = function()
Runtime:removeEventListener( "enterFrame", startRotation )
end
local hideTarget = transition.to( target, { alpha=0, xScale=1.0, yScale=1.0, time=200, onComplete=stopRotation } )
if ( myLine ) then
myLine.parent:remove( myLine )
end
createobj2(t.x,t.y)
obj2:applyForce( (t.x - event.x), (t.y - event.y), t.x, t.y )
end
end
return true
end
physicsObjStatic:addEventListener( "touch", Shot )