Sdk 当物体运动时,电晕物理学会时断时续

Sdk 当物体运动时,电晕物理学会时断时续,sdk,physics,coronasdk,game-physics,bulletphysics,Sdk,Physics,Coronasdk,Game Physics,Bulletphysics,下面是我的主要文件。从本质上说,当“rect”对象不移动时,碰撞正在发生,但只要我移动rect对象,碰撞就停止生效。我认为它知道它在碰撞,但它并没有做任何事情(比如和物体的交互)。有没有人有什么想法,为什么会这样?如何修复它 local physics = require("physics") ; physics.start() ; physics.setGravity( 0,0 ) ; physics.setDrawMode( "debug" ) display.setStatusBar(

下面是我的主要文件。从本质上说,当“rect”对象不移动时,碰撞正在发生,但只要我移动rect对象,碰撞就停止生效。我认为它知道它在碰撞,但它并没有做任何事情(比如和物体的交互)。有没有人有什么想法,为什么会这样?如何修复它

local physics = require("physics") ; physics.start() ; physics.setGravity( 0,0 ) ; 
physics.setDrawMode( "debug" )
display.setStatusBar( display.HiddenStatusBar )
math.randomseed( os.time() )

physics.setVelocityIterations(10);
physics.setPositionIterations(20);


--set up some references and other variables
local ox, oy = math.abs(display.screenOriginX), math.abs(display.screenOriginY)
local cw, ch = display.contentWidth, display.contentHeight

--set up collision filters
local screenFilter = { categoryBits=2, maskBits=1 }
local objFilter = { categoryBits=1, maskBits=14 }
local fieldFilter = { categoryBits=4, maskBits=1 }
local magnetFilter = { categoryBits=8, maskBits=1 }

--set initial magnet pull
local magnetPull = 0.25

--set up world and background
local screenBounds = display.newRect( -ox, -oy, display.contentWidth+ox+ox, display.contentHeight+oy+oy )
screenBounds.name = "screenBounds"
screenBounds.isVisible = false ; physics.addBody( screenBounds, "static", { isSensor=true,     filter=screenFilter } )


local function newPositionVelocity( object )
    local math_random = math.random    
    local side = math_random( 1,4 ) ; local posX ; local posY ; local velX ; local velY

if ( side == 1 or side == 3 ) then
    posX = math_random(0,display.pixelHeight)
    velX = math_random( -10,10 ) * 5
    if ( side == 1 ) then posY = -oy-40 ; velY = math_random( 8,18 ) * 16
    else posY = display.contentHeight+oy+40 ; velY = math_random( 8,16 ) * -16
    end
else
    posY = math_random(0,display.pixelWidth)
    velY = math_random( -10,10 ) * 5
    if ( side == 4 ) then posX = -ox-40 ; velX = math_random( 8,16 ) * 16
    else posX = display.contentWidth+ox+40 ; velX = math_random( 8,16 ) * -16
    end
end
object.x = posX ; object.y = posY
object:setLinearVelocity( velX, velY )
object.angularVelocity = math_random( -3,3 ) * 40
object.alpha = 1

end

local rect = display.newRect(100,100,100,60);
local offset = 250
rect.x = cw/2;
rect.y = ch/2-offset;
--rect.xReference = 40;
rect.yReference = offset;



local function objectCollide( self, event )
local otherName = event.other.name
print(event.other.name);

local function onDelay( event )
    local action = ""
    if ( event.source ) then action = event.source.action ; timer.cancel( event.source ) end

    if ( action == "makeJoint" ) then
        self.hasJoint = true
        self.touchJoint = physics.newJoint( "touch", self, self.x, self.y )
        self.touchJoint.frequency = magnetPull
        self.touchJoint.dampingRatio = 0.0
        self.touchJoint:setTarget( 512, 384 )
    elseif ( action == "leftField" ) then
        self.hasJoint = false ; self.touchJoint:removeSelf() ; self.touchJoint = nil
    else
        if ( self.hasJoint == true ) then self.hasJoint = false ; self.touchJoint:removeSelf() ; self.touchJoint = nil end
        newPositionVelocity( self )
    end
end

if ( event.phase == "ended" and otherName == "screenBounds" ) then
    local tr = timer.performWithDelay( 10, onDelay ) ; tr.action = "leftScreen"
elseif ( event.phase == "began" and otherName == "magnet" ) then
    transition.to( self, { time=400, alpha=0, onComplete=onDelay } )
elseif ( event.phase == "began" and otherName == "field" and self.hasJoint == false ) then
    local tr = timer.performWithDelay( 10, onDelay ) ; tr.action = "makeJoint"
elseif ( event.phase == "ended" and otherName == "field" and self.hasJoint == true ) then
    local tr = timer.performWithDelay( 10, onDelay ) ; tr.action = "leftField"
end


end



local function setupWorld()

for i=1, 20 do
    local obj = display.newCircle(0,0, 12 )
    physics.addBody( obj, "dynamic", { bounce=.3, radius=12, density = .2 --[[,filter=objFilter]] } )
    obj. isBullet = true;
            newPositionVelocity( obj )
    obj.hasJoint = false
    obj.collision = objectCollide ; obj:addEventListener( "collision", obj )
end

local field = display.newCircle(cw/2, ch/2, 320); 
    field.alpha = 0.2;
field.name = "field";
field.x = display.contentCenterX ; field.y = display.contentCenterY;
physics.addBody( field, "static", { isSensor=true, radius=320, filter=fieldFilter });

magnet = display.newCircle(cw/2, ch/2, 40 )
magnet.name = "magnet"
magnet.x = display.contentCenterX ; magnet.y = display.contentCenterY
physics.addBody( magnet, "static", { bounce=0, radius=40, filter=magnetFilter } )

  end

 setupWorld()
 physics.addBody(rect,"kinematic", { bounce = 1, density = 1})


 deg = 0.0;
 prevY = 0;
 local function onTouch(event)
 if event.phase == "began" then
  prevY = event.y
end
if (deg<=360) then
  deg=0;
end

if(event.y >= prevY) then
   deg = deg + 10;
elseif(event.y <= prevY) then
   deg = deg -10;
end  
prevY = event.y

rect:rotate(deg);

end


Runtime:addEventListener("touch", onTouch);
本地物理=要求(“物理”);物理。开始();物理学.重力场(0,0);
physics.setDrawMode(“调试”)
display.setStatusBar(display.HiddenStatusBar)
math.randomseed(os.time())
物理学.设定速度迭代(10);
《物理学》(20);
--设置一些引用和其他变量
本地ox,oy=math.abs(display.screenOriginX),math.abs(display.screenOriginY)
本地cw,ch=display.contentWidth,display.contentHeight
--设置冲突过滤器
本地screenFilter={categoryBits=2,maskBits=1}
局部objFilter={categoryBits=1,maskBits=14}
本地字段筛选器={categoryBits=4,maskBits=1}
局部magnetFilter={categoryBits=8,maskBits=1}
--设置初始磁铁拉力
局部磁拉力=0.25
--建立世界和背景
本地屏幕边界=display.newRect(-ox,-oy,display.contentWidth+ox+ox,display.contentHeight+oy+oy)
screenBounds.name=“screenBounds”
screenBounds.isVisible=false;addBody(screenBounds,“static”,{isSensor=true,filter=screenFilter})
局部函数newPositionVelocity(对象)
本地math_random=math.random
局部侧=数学随机(1,4);局部posX;局部波西;局部绒毛;地方政府
如果(边==1或边==3),则
posX=数学随机(0,显示像素高度)
velX=数学随机(-10,10)*5
如果(边==1),则posY=-oy-40;velY=数学随机(8,18)*16
else posY=display.contentHeight+oy+40;velY=数学随机(8,16)*-16
结束
其他的
posY=math_random(0,display.pixelWidth)
velY=数学随机(-10,10)*5
如果(side==4),那么posX=-ox-40;velX=数学随机(8,16)*16
else posX=display.contentWidth+ox+40;velX=数学随机(8,16)*-16
结束
结束
object.x=posX;object.y=posY
对象:setLinearVelocity(velX、VEL)
object.angularVelocity=数学随机(-3,3)*40
object.alpha=1
结束
本地rect=display.newRect(100100,60);
本地偏移=250
矩形x=cw/2;
矩形y=通道/2-偏移;
--rect.xReference=40;
rect.yReference=偏移量;
局部函数objectCollide(self,event)
本地otherName=event.other.name
打印(事件.其他.名称);
本地函数onDelay(事件)
本地操作=“”
如果为(event.source),则action=event.source.action;计时器.取消(event.source)结束
如果(action==“makeJoint”),则
self.hasJoint=true
self.touchJoint=physics.newJoint(“touch”,self,self.x,self.y)
self.touchJoint.frequency=magnetPull
self.touchJoint.dampingRatio=0.0
self.touchJoint:setTarget(512,384)
elseif(action==“leftField”),然后
self.hasJoint=false;self.touchJoint:removeSelf();self.touchJoint=nil
其他的
如果(self.hasJoint==true),则self.hasJoint=false;self.touchJoint:removeSelf();自接触接头=零端
新位置速度(自)
结束
结束
如果(event.phase==“ended”和otherName==“screenBounds”),则
本地tr=定时器。延时性能(10,onDelay);tr.action=“左屏幕”
elseif(event.phase==“开始”和otherName==“磁铁”),然后
到(self,{time=400,alpha=0,onComplete=onDelay})
elseif(event.phase==“start”和otherName==“field”和self.hasJoint==false),然后
本地tr=定时器。延时性能(10,onDelay);tr.action=“makeJoint”
elseif(event.phase==“end”和otherName==“field”和self.hasJoint==true),然后
本地tr=定时器。延时性能(10,onDelay);tr.action=“leftField”
结束
结束
本地函数setupWorld()
对于i=1,20 do
本地对象=显示。新圆(0,0,12)
addBody(obj,“dynamic”{bounce=.3,radius=12,density=.2--[,filter=objFilter]})
obj。isBullet=true;
新位置速度(obj)
obj.hasJoint=false
obj.collision=对象碰撞;obj:addEventListener(“碰撞”,obj)
结束
本地字段=显示新圆圈(cw/2,ch/2,320);
field.alpha=0.2;
field.name=“field”;
field.x=display.contentCenterX;field.y=display.contentCenterY;
addBody(field,“static”{isSensor=true,radius=320,filter=fieldFilter});
磁铁=显示器。新圆圈(cw/2,ch/2,40)
magnet.name=“magnet”
magnet.x=display.contentCenterX;magnet.y=display.contentCenterY
addBody(磁铁,静态,{bounce=0,radius=40,filter=magnetFilter})
结束
setupWorld()
addBody(rect,“运动学”{bounce=1,density=1})
deg=0.0;
prevY=0;
本地函数onTouch(事件)
如果event.phase==“开始”,则
prevY=event.y
结束
如果(度数=上一个度数),则
度=度+10;

elseif(event.y运动学物体不会产生碰撞。它需要是动态的。

听起来你的身体好像要睡觉了

尝试:

rect.isSleepingAllowed=false