Corona中的Lua相等问题

我正在开发一个Android应用程序,但是Corona似乎没有正确识别fish1display.contentWidth/3+20的位置。当fish1display.contentWidth/3+20时,会产生一个新的气泡newBubble,并且它出现在与鱼相同的x轴上。

bubbleDivision = display.contentWidth/3 -- Bubbles出现的数量
print (bubbleDivision)

if fish1.x == display.contentWidth/3 + 20 then
    newBubble = display.newImage("testBubble.png")
    print "产生了新气泡"

    newBubble.x = fish1.x
end
点赞
用户1190388
用户1190388

很可能是浮点数错误。使用math.floormath.ceil,看哪个适用/合适。

bubbleDivision = math.floor( display.contentWidth / 3 )
if math.floor(fish1.x) == bubbleDivision + 20 then
2015-10-12 08:22:09