physics.addBody()
仅适用于圆形和矩形吗?或者可以physics.addBody()
对矢量形状或精灵或面具或其他东西?
答案 0 :(得分:1)
可以使用精灵和形状,请参阅here。
local physics=require("physics")
physics.start()
physics.setDrawMode("hybrid")
local obj=display.newRect(160,600,50,50)
physics.addBody(obj,"static", {density=0.1,friction=0.1} )
local obj=display.newCircle(90,500,50)
physics.addBody(obj, "static", {density=0.1,friction=0.1,radius=50} )
--equilateral triangle physics object
local rad=30/360*2*math.pi
local xHalfLen=80*math.sin(rad)
local yLen=80*math.cos(rad)
local obj=display.newLine(100,100, 100+xHalfLen,100+yLen)
obj:append(100-xHalfLen,100+yLen, 100,100)
obj.width=3
obj:setColor(255,120,120)
local triangleShape={0,0, xHalfLen,yLen, -xHalfLen,yLen}
--center of object is at top of triangle
physics.addBody(obj, {density=0.1,friction=0.1,shape=triangleShape} )
形状必须是凸面的,并且由少于8个边组成。