Game Development Reference
In-Depth Information
In the first case, someValueOn will return true as long as someValueOn is not nil or false . However, if
someValueOn were − 1 or " Off ", the statement would still evaluate to true , whereas in the second line,
someValueOn==true would return a true only if the value were true , and in no other circumstance.
Translating C/Java Like Loops to Lua
If you come from a Java/C/C++ or JavaScript background, you should be used to loops like this:
for (initialize; condition; iteration){
}
initialize , each separated with a comma. The condition can be
if score < 100 then
break
end
-- Do whatever here
k = k - 1
end
Applying Friction to an Object
The easiest way to move an object around the screen is to move it at constant speed (i.e., increase
or decrease the axis value by the same value over time). This behavior is of course quite unrealistic.
For example, in the real world, when a box is pushed across the hall, it moves fast at first and then
it gradually slows down until it finally stops. One shortcut that a lot of developers prefer is to use a
physics object; it works, but we can simulate friction without using a physics object with the help of
a little math.
local speed = 20
local friction = 0.9
repeat
print(speed)
speed = speed * friction
until speed <= 1
 
Search WWH ::




Custom Search