我不知道为什么我的代码不起作用。如果他面前的角色静止,我只想阻止下一个角色。我的想法是在他们的线速度为 0 时设置线性速度(0,0),以便下一个角色知道当他面前的角色的线速度为 0 时他必须停止。
local function loopPg()
local runningPG = display.newSprite(pg[math.random(5)], sequences_runningPG)
runningPG.x = display.contentCenterX
runningPG.y = display.contentCenterY-730
runningPG:scale(0.75, 0.75)
runningPG:play()
physics.addBody(runningPG, "dynamic", {radius = 55})
local function pathPg()
if(runningPG.y >= -190 and runningPG.y < 160) then
runningPG:setLinearVelocity(0,250)
elseif (runningPG.y >= 160 and runningPG.x >= 220) then
runningPG:setLinearVelocity(-250,0)
elseif (runningPG.x <= 220 and runningPG.y <= 635) then
runningPG:setLinearVelocity(0,250)
elseif ( runningPG.y >= 635) then
runningPG:setLinearVelocity(0,0)
end
end
local vx,vy = runningPG:getLinearVelocity()
if(vx == 0 and vy == 0) then
runningPG:setLinearVelocity(0,0)
end
Runtime:addEventListener( "enterFrame", pathPg )
end
timer.performWithDelay(600, loopPg, 3)