【发布时间】:2016-05-03 09:51:39
【问题描述】:
我正在尝试制作一个小型无尽的跑步游戏,其中玩家(一个小盒子)在平台之间左右移动。我注意到播放器被挖掘到平台中。我尝试调整玩家物理体和平台物理体的密度。但他们都没有工作。这和anchorX,anchorY有关系吗?
local physics = require('physics')
physics.start()
player = display.newImageRect('boxy.png',30,30)
player.anchorX = 0
player.anchorY = 0
player.x = 200
physics.addBody(player,'dynamic', {density = 1, friction = 0, bounce = 0})
platformLeft = display.newRect(100,300,450,30)
platformLeft:setFillColor(0,0,0)
platformLeft.anchorX = 1
platformLeft.anchorY = 0.5
platformLeft.x = (width - 1) * 30
platformLeft.y = _H + 90
physics.addBody(platformLeft,'static', {density = 1, friction = 0, bounce = 0})
platgroup:insert(platformLeft)
platformRight = display.newRect(100,350,450,30)
platformRight:setFillColor(0,0,0)
platformRight.anchorX = 0
platformRight.anchorY = 0.5
platformRight.x = width * 30
platformRight.y = _H + 90
physics.addBody(platformRight,'static', {density = 1,friction = 0, bounce = 0})
platgroup:insert(platformRight)
【问题讨论】:
-
您应该提供“挖掘平台”情况的屏幕截图,或者至少说明它们重叠的程度。
-
已上传。如您所见,几乎一半的盒子都被盖住了。
-
如果您认为它可能与anchorX和anchorY有关,您是否尝试更改它们,看看会发生什么?也检查docs.coronalabs.com/api/library/physics/setDrawMode.html进行调试