我正在建立一个平台跳线,当球穿过平台时,我希望它出现在平台前面,而不是后面。我已经尝试将两个对象按照正确的顺序放入一个新的显示组中,然后使用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( )
答案 0 :(得分:2)
你把球按错误顺序排列,应该是
local group = display.newGroup( )
group:insert( platform )
group:insert( ball )