Game Development Reference
In-Depth Information
Threading
By default, all of the functions used to transform Moai objects are nonblocking and are executed
in parallel. For example, if we have transforms on a prop, they will all be executed simultaneously.
Here's an example:
prop:moveLoc(180, 180, 3)
prop:moveScl(1.2,1.2,1)
prop:moveLoc(-180,-180,3)
prop:moveScl(0.9,0.9,1)
Moai can perform all these transformations at the same time; if you were to run this code, you would
see only the end result of the four transforms, rather than each individual one.
Moai has the concept of threads; we had a look at them and coroutines in earlier chapters. We can
create blocking threads in Moai so that we can run each of the actions in blocking mode. Here's
an example:
function threadFunction()
action = prop:moveLoc(180, 180, 3.0)
MOAIThread.blockOnAction(action)
action = prop:moveScl(1.2, 1.2, 1.0)
MOAIThread.blockOnAction(action)
action = prop:moveLoc(-180, -180, 3.0)
MOAIThread.blockOnAction(action)
action = prop:moveScl(0.8, 0.8, 1.0)
MOAIThread.blockOnAction(action)
end
thread = MOAIThread.new()
thread:run(threadFunction)
The blocking actions that we create can be run only for action items (transformations).
Groups
The definition of groups as described by other frameworks is that of a container—one that holds all
the other display objects. Generally, groups are nonvisual display objects. With Moai, the concept is
a bit different—you can set up a parent-child relation between two objects. When the parent object
is modified or moved, the child object follows suit, as shown in Figure 10-8 .
 
Search WWH ::




Custom Search