如何在corona中使用图像制作宽度覆盖整个屏幕高度为40像素的底部地面。

如何利用 Corona 从图片制作地板? 我想将图像拉伸到 contentWidth 为宽度,高度为 40,但尝试时它会显示奇怪的效果。高度上有关于图像的物体,并且在宽度上有物理上的洞孔(在两侧都可以穿过)。 我想创建一张地板图像,使其不受手机分辨率的影响,并且物体不能穿过(物体具有自己的 body 和 material) 。

点赞
用户2260604
用户2260604

这是因为在缩放一个对象时使用了 horizPost:scale( 2, 0.5 ) ,你只是在缩放图像而不是应用于它的物理效果。

以下解决方案将在任何分辨率下按照你的要求适应屏幕。

local horizPost = display.newImage( "images/floor.png", display.contentWidth,  40)
horizPost.x = display.contentWidth / 2
horizPost.y = display.contentHeight - 40
horizPost.width = display.contentWidth -- 替换了你的 horizPost:scale(2,0.5)
staticMaterial = {density=10, friction=1, bounce=1}
physics.addBody(horizPost, "static", staticMaterial)
2014-06-29 16:23:15