Game Development Reference
In-Depth Information
setLoc and getLoc are basically convenience methods that are used to access attributes from props.
Another convenience method that is quite useful is moveRot , which is used to rotate the object by a
particular angle over a specified period of time.
prop:moveRot(180, 2)
This code will rotate the prop 180 degrees over a period of 2 seconds.
MOAIEaseDriver can operate on attributes directly; we can simply specify the objects and attributes
to operate on. MOAIEaseDriver applies simple ease curves to node attributes. Here's an example of
its use.
ease = MOAIEaseDriver.new()
ease:reserveLinks(3)
ease:setLink(1, prop, MOAIProp2D.ATTR_X_LOC, 64)
ease:setLink(2, prop, MOAIProp2D.ATTR_Y_LOC, 64)
ease:setLink(3, prop, MOAIProp2D.ATTR_Z_ROT, 360)
ease:start()
This code snippet creates an ease driver, and then sets each channel to target a specific attribute of a
single prop. This will rotate and move the prop from the top-left corner of the screen to a new location.
Note When you set the parent-child relation (and also a dependency) between two props (called
graph nodes), the parent node is updated first and then the child node.
Tile Decks
Earlier in the chapter I described the various types of decks you can use. In this section, we'll take a
closer look at MOAITileDeck2D , which helps create frame-by-frame animation. The sprite sheet for a
TileDeck2D requires all of the frames to be of the same size. Then when you load the texture, you set
the number of frames across and the number of frames down. Since the dimensions of all the frames
are the same, when you set the size using the setSize function, the sprite sheet will be divided into
an equal numbers of frames, as specified by the function. The dimensions are calculated as follows:
frameWidth = spriteSheetWidth / columns
frameHeight = spriteSheetHeight / rows
The following example shows how you can use frame animation. The results of the code are shown
in Figure 10-6 .
 
 
Search WWH ::




Custom Search