【问题标题】:In Corona SDK, How do I keep a player from being dug into platforms?在 Corona SDK 中,如何防止玩家被平台挖走?
【发布时间】: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进行调试

标签: lua coronasdk


【解决方案1】:

尝试向物理体添加形状。

Corona - Physics - Add Body

正如 Piglet 上面提到的,尝试将物理绘制模式设置为混合,这对于调试非常有用。

【讨论】:

    猜你喜欢
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 2014-02-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多