문제

shape:setY(math.random(0, 450 - 50))

math.random function with a minimum and a maximum value is what I understand but what exactly is the meaning of using arithmetic operator in mat.random function, say in above LOC, why is it 450 - 50 and not 400? what is the difference?

similarly,

self:setPosition(540, math.random(160) + 40)
도움이 되었습니까?

해결책

There is no difference. It is equivalent to shape:setY(math.random(0, 400)).

The second line of code is equivalent to the following:

self:setPosition(540, math.random(1, 160) + 40)

It is most certainly intended to be a clearer and/or simpler way of writing

self:setPosition(540, math.random(41, 200))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top