How to make display to have frame around to avoid ball getting out of display?

a 夏天 提交于 2019-12-08 08:16:58

问题


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 topFrameand 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!