Game Development Reference
In-Depth Information
for i=1,_max_ do
curve:setKey(i, i*(1/_max_), i, MOAIEaseType.FLAT)
end
anim = MOAIAnim:new()
anim:reserveLinks(1)
anim:setLink(1, curve, prop1, MOAIProp2D.ATTR_INDEX)
anim:setMode(MOAITimer.LOOP)
anim:start()
prop1:setLoc(100,100)
In this example, we first create the tiles that we can use for our animation:
tile = MOAITileDeck2D.new()
tile:setTexture("stick.png")
tile:setSize(11,1)
tile:setRect(-20,31,20,-31)
Our sprite sheet has 11 frames across and 1 frame down (see Figure 10-7 ). The dimensions of all the
frames are 40×62, which we set with setRect .
Figure 10-7. The stick.png image that we shall use for the animation
Setting a negative value for the rect dimensions in the setRect function flips the object on the axis
with the negative value. Since Moai has an ascending y-axis, we change the scale to set the top-left
corner as the origin (0,0), so our images will show up flipped on the y-axis. To correct that, we use
the setRect function with tile:setRect(-20,31,20,-31) instead of tile:setRect(-20,-31,20,31) .
prop1 = MOAIProp2D.new()
prop1:setDeck(tile)
layer:insertProp(prop1)
We create a MOAIProp2D object and set the tile we just created to the prop's deck, and then we insert
that prop in the layer:
curve = MOAIAnimCurve.new()
_max_ = 11
curve:reserveKeys(_max_)
for i=1, _max_ do
curve:setKey(I, I * (1/_max_), I, MOAIEaseType.FLAT)
end
We create a MOAIAnimCurve object and then designate the number of frames using the reserveKeys
function. Then we create the frames and set the index and the time index for each of the frames,
Search WWH ::




Custom Search