添加'';物理学.addBody'';本地imgpath lua

添加'';物理学.addBody'';本地imgpath lua,lua,coronasdk,corona-storyboard,Lua,Coronasdk,Corona Storyboard,通过添加解决 if ( temp.imgpath == "badcloud.png" ) then physics.addBody( randomcloud, "static", { density=.1, bounce=.1, friction=.2, radius=45 } ) end ============================================================================ 我想向cloud4添加一个physics.add

通过添加解决

if ( temp.imgpath == "badcloud.png" ) then
  physics.addBody( randomcloud, "static", { density=.1, bounce=.1, friction=.2, radius=45 } )
end
============================================================================

我想向cloud4添加一个
physics.addBody
,这样它就可以与
运行时进行交互:addEventListener(“碰撞”,onCollision)
,但是如果我这样做:

local cloud4 = {}
physics.addBody(cloud4, "static", {densit=.1, bounce=0.1, friction=.2, radius=45})
cloud4.imgpath = "badcloud.png";
cloud4.movementSpeed = 18000;
table.insert(cloudTable, cloud4);
如果参数错误,如何解决

function initcloud()
    local cloud1 = {}
    cloud1.imgpath = "cloud1.png"; --Set Image Path for cloud
    cloud1.movementSpeed = 10000; --Determines the movement speed of cloud
    table.insert(cloudTable, cloud1); --Insert cloud into cloudTable

    local cloud2 = {}
    cloud2.imgpath = "cloud2.png";
    cloud2.movementSpeed = 12000;
    table.insert(cloudTable, cloud2);               

    local cloud3 = {}
    cloud3.imgpath = "cloud3.png";
    cloud3.movementSpeed = 14000;
    table.insert(cloudTable, cloud3);

    local cloud4 = {}
    cloud4.imgpath = "badcloud.png";
    cloud4.movementSpeed = 18000;
    table.insert(cloudTable, cloud4);   

    local cloud5 = {}
    cloud5.imgpath = "cloud5.png";
    cloud5.movementSpeed = 21000;
    table.insert(cloudTable, cloud5);
end --END initcloud()

完整代码

function createClouds()
function initcloud()
    local cloud1 = {}
    cloud1.imgpath = "cloud1.png"; --Set Image Path for cloud
    cloud1.movementSpeed = 10000; --Determines the movement speed of cloud
    table.insert(cloudTable, cloud1); --Insert cloud into cloudTable

    local cloud2 = {}
    cloud2.imgpath = "cloud2.png";
    cloud2.movementSpeed = 12000;
    table.insert(cloudTable, cloud2);               

    local cloud3 = {}
    cloud3.imgpath = "cloud3.png";
    cloud3.movementSpeed = 14000;
    table.insert(cloudTable, cloud3);

    local cloud4 = {}
    cloud4.imgpath = "badcloud.png";
    cloud4.movementSpeed = 18000;
    table.insert(cloudTable, cloud4);   

    local cloud5 = {}
    cloud5.imgpath = "cloud5.png";
    cloud5.movementSpeed = 21000;
    table.insert(cloudTable, cloud5);


end --END initcloud()   

function getRandomcloud()
local temp = cloudTable[math.random(1, #cloudTable)] -- Get a random cloud from cloudTable
local randomcloud = display.newImage(temp.imgpath);
randomcloud.myName = "cloud";
randomcloud.movementSpeed = temp.movementSpeed; -- set the cloud cloudting point
randomcloud.x = math.random(10, _W);
randomcloud.y = -35;
randomcloud.rotation = math.random(0, 20); -- move the cloud
cloudMove = transition.to(randomcloud, {
time = randomcloud.movementSpeed, 
y = 500,
onComplete = function(self)
self.parent:remove(self);
self = nil;
end 
});
end

function cloudtGame()
    cloudTimer1 = timer.performWithDelay(3000,getRandomcloud, 5)
    cloudTimer2 = timer.performWithDelay(2000,getRandomcloud, 0)
    cloudTimer3 = timer.performWithDelay(2400,getRandomcloud, 0)    
    cloudTimer4 = timer.performWithDelay(7000,getRandomcloud, 0)    
    cloudTimer5 = timer.performWithDelay(9000,getRandomcloud, 0)        
end--END cloudtGame()
initcloud()
cloudtGame()
end
线路

physics.addBody(cloud4, "static", {densit=.1, bounce=0.1, friction=.2, radius=45})
有一个打字错误,导致错误。它应该是
density
,而不是
densit
。像这样:

physics.addBody( cloud4, "static", { density = .1, bounce = 0.1, friction = .2, radius = 45 } )
通过添加

if ( temp.imgpath == "badcloud.png" ) then
  physics.addBody( randomcloud, "static", { density=.1, bounce=.1, friction=.2, radius=45 } )
end

“addBody”的错误参数#-1对象不需要
x
y
值吗?将
cloud4.x=0
cloud4.y=0
添加到
physics.addBody()调用之前。x和y值基于:函数getRandomcloud()。randomcloud.x=数学随机(10,W);y=-35;您在哪里调用了它?@kevinver您在调用addBody之前,可以指定它的
x
y
值。。