如何使显示器周围有框架以避免球脱出显示器? [英] How to make display to have frame around to avoid ball getting out of display?

查看:93
本文介绍了如何使显示器周围有框架以避免球脱出显示器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作带球的简单游戏,但是如何使显示周围有框架以避免球脱出显示呢? 我想在那个框架上有个小孔,这样球才能最终掉出来.我这样做就像在显示周围放置几个矩形(宽度或高度为1px,其他尺寸较大),但是当球具有较大的速度时,它将穿过墙壁.有更好的解决方案吗?

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.

推荐答案

将物理物体添加到框架中,以使球不会穿过框架

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 } )

别忘了在代码顶部启动物理引擎"physics.start()"

Don't forget to start the physics engine "physics.start()" on the top of your code

P.S只需修改topFrame并在两侧和底部再创建三堵墙.

P.S just modify the the topFrameand create another three walls on both side and on the bottom.

这篇关于如何使显示器周围有框架以避免球脱出显示器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆