Game Development Reference
In-Depth Information
All of the four steps are now expressed as actions in the code of the
buildObjectLayer() method. This code replaces the setPosition() for the
corresponding images. The origin of the gold coins' image that is stored in imgCoins
needs to be adjusted so that it now points to its center. In this way, the image does
not only grow or shrink when scaled but it will never move away from its original
position. The first action of imgCoins is sequence() that merely groups all other
actions. Then, the animation is initialized through the first three actions: moveTo() ,
scaleTo() , and fadeOut() . Next, a delay() action follows that creates a short delay
of 2.5 seconds before the parallel action is executed.
The parallel action contains three more actions, moveBy() , scaleTo() , and alpha() ,
which are all executed at the same time. These three actions, when played together,
create the impression that the gold coins appear to jump out of the water by moving
them a bit downwards as well as fading them in and scaling them up from 0 percent
to 100 percent. Interpolations are also used to support this effect. Choosing the right
interpolation algorithm is usually a little trial-and-error at first, but after a while you
will have a better understanding and feel for which one could work best for certain
kinds of effects.
The animation for the bunny head is not that much different to the gold coins. It
starts with a grouping sequence() that comprises an initializing moveTo() action
followed by a delay() of 4 seconds. Then, three subsequent moveBy() actions are
executed that describe the complete movement we discussed earlier.
Animating the menu buttons and options
window
Now, for a final touch to the menu screen, let's animate the menu buttons in the
bottom-right corner of the scene as well as the Options window that appears when
the Options button is clicked. We want to let both buttons move out of the scene
when the Options button is clicked on and let them move back into the scene after
the Options window is closed again.
Add the following import lines to the MenuScreen class:
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
import com.badlogic.gdx.scenes.scene2d.Touchable;
 
Search WWH ::




Custom Search