在Corona SDK中将一个对象放在另一个对象的前面

我正在构建一个平台跳跃游戏。当球穿过平台时,我希望它出现在平台前面而不是后面。我尝试将两个对象放在正确的顺序中一个新的显示组中,并使用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 )

-- 添加物理效果到球上
physics.addBody( ball, "dynamic", { density=1.0,
                friction=0.9, bounce=0 } )

-- 创建一个具有物理效果的平台
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 } )

-- 平台在中间位置
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 } )

-- 将球放在前面
local group = display.newGroup( )
group:insert( ball )
group:insert( platform )

ball:toFront( )
点赞
用户3803880
用户3803880

你把球放错顺序了,应该是

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

请查看组结构

2014-12-15 01:39:39