问题
I am trying to make simple game with ball but how to make display to have frame around to avoid ball getting out of display ? I want to have small hole in that frame so ball eventually can get out. I done this like putting couple rectangles ( with width or height 1px and other dimension is larger ) around display but when ball has large speed it pass through wall. Is there better solution for this.
回答1:
Add physics body to the frame so that the ball will not pass through it
local topWall = display.newRect(0,0,display.contentWidth,2)
physics.addBody( topWall, "static", { friction = 0.5, bounce = 0 } )
Don't forget to start the physics engine "physics.start()
" on the top of your code
P.S just modify the the topFrame
and create another three walls on both side and on the bottom.
回答2:
just make rect wider like 300px.
also you can try to set parameter ball.isBullet = true it will tell physics engine to keep eye on ball to avoid getting it through walls
来源:https://stackoverflow.com/questions/26823313/how-to-make-display-to-have-frame-around-to-avoid-ball-getting-out-of-display