【问题标题】:Placing one object in front of another in Corona SDK在 Corona SDK 中将一个对象放在另一个对象前面
【发布时间】:2014-12-23 19:09:06
【问题描述】:

我正在构建一个跳台跳投,当球通过平台时,我希望它出现在平台的前面,而不是后面。我尝试将这两个对象以正确的顺序放入一个新的显示组中,并使用toFront() 将球发送到前面,但我无法让它工作。有什么想法吗?

local ball = display.newCircle( 100, 100, 30 )
ball.id = "ball"
ball.x, ball.y = 160, 350
ball.rotation = 15

local gradient = {
    type="gradient",
    color1={ 1, 4, 7 }, color2={ .1, 1, 1.5}, direction="down"
                }
ball:setFillColor( gradient )

-- add physics to the ball
physics.addBody( ball, "dynamic", { density=1.0,
                friction=0.9, bounce=0 } )

-- create a platform w/ physics
local bottom = display.newRect( 0, 0, 320, 100 )
bottom.anchorX = 0
bottom.anchorY = 1
bottom.x, bottom.y = 0, display.contentHeight

physics.addBody( bottom, "static", { friction=0.3 } )

-- put plat in middle
local platform = display.newRect( 0, 0, screenW-100, screenH-450 )
platform.x, platform.y = 160, 200
platform.collType = "passthru"
physics.addBody( platform, "static", { bounce=0.0, friction=0.3 } )

-- place ball in front
local group = display.newGroup( )
group:insert( ball )
group:insert( platform )

ball:toFront( )

【问题讨论】:

    标签: lua coronasdk


    【解决方案1】:

    你的球顺序不对,应该是

    local group = display.newGroup( )
    group:insert( platform )
    group:insert( ball )
    

    看看Group Hierarchy

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-13
      • 2017-01-02
      • 1970-01-01
      相关资源
      最近更新 更多