Game Development Reference
In-Depth Information
private function changePage( _direction:int ):void
{
mCurrentPage += _direction;
mCurrentPage = ( mCurrentPage < 1)?1:mCurrentPage;
mCurrentPage = ( mCurrentPage > NUMBER_OF_PAGES ) ?
NUMBER_OF_PAGES: mCurrentPage;
var targetX:int = ( mCurrentPage - 1 ) * -loaderInfo.width;
TweenNano.to( clipRulesText, .25, { x: targetX, ease:
Quad.easeInOut } );
}
In the onGestureSwipe event handler, we simply use the offset
property of the event to determine if they swiped from left to right
(positive) or right to left (negative). However, the behavior we
re
expecting is the inverse. When swiping from right to left, the user
wants to advance to the content on the right and vice versa for
going from left to right. This is handled by the changePage method,
which determines the new page to display and uses TweenNano to
slide the text clip around on stage. The net result is very natural,
similar to the native swiping used for menus in the Android OS.
Now that we
'
'
re done with the ancillary components to our
game, let
'
s dig into the gameplay itself. We
'
ll start with the touch
controller, so you
'
ll have context for what it does in the game.
Then, we
ll look at the application end of the game and how it
manages states. We
'
'
ll finish out the game with the engine and how
it drives the physics.
GameTouchController.as
As you saw in the main document class, when we enter the game
state of the application, we changed to the touch point form of
multitouch input. This will give us the flexibility we need for two
active players. The GameTouchController class is linked directly to
a display object on stage. In this case, there are two of them, one
for each side of the game board. They are on the layer input zones
in the XFL file, inside of the game clip. They are simply shapes
filled with a transparent color, so they will receive input events but
not be visible. Now let
'
s take a look at the code.
public class GameTouchController extends Sprite
{
private var mPosition:Point;
private var mCoordinateSpace:DisplayObjectContainer;
private var mDistanceThreshold:Number;
private var mTouching:Boolean = false;
public function GameTouchController()
Search Nedrilad ::




Custom Search