简体   繁体   中英

Lua Equal To issue in Corona

I'm currently developing an android app and I'm having an issue with corona not registering that fish1 is at display.contentWidth/3 + 20 . When fish1 is at display.contentWidth/3 + 20 then a newBubble is made and it appears on the x axis where the fish is.

bubbleDivision = display.contentWidth/3 -- How many times the Bubbles will appear
print (bubbleDivision)

if fish1.x == display.contentWidth/3 + 20 then
    newBubble = display.newImage("testBubble.png")
    print "Spawned"

    newBubble.x = fish1.x       
end

Most probably, it is a floating point error. Use math.floor or math.ceil , whichever is applicable/suitable.

bubbleDivision = math.floor( display.contentWidth / 3 )
if math.floor(fish1.x) == bubbleDivision + 20 then

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM