4. How to implement touch control operation
Touch Operations Overview:
With Apple, Samsung, Sony and many other companies, the handheld, computers and mobile phones and other products in the touch of the field of continuous exploration, to touch the operating models more and more are put into the market. A large number of touch-control games, touch software has been developed and applied, announcing the arrival of the era of touch control. As a game that has always been a popular player, the game of parkour has been transplanted to the touch-control platform. When Touch game operation interface, get rid of the traditional point control operation, how to realize the player and game interaction? This is compared to the previous parkour game, we need to first on the trackpad operation instructions to determine, and then the game role according to the corresponding instructions to perform the corresponding operation.
Principle:
As shown in Figure 4-1
Figure 4-1
Implementation method:
Step 1:
In the main cycle of the game will be the movement of input to do tick detection, in the tick, will record the coordinates of the finger movement position.
if (input.getscreentouchcount () = = 1)
02 {
The int id = input.getscreentouchid (0);
if (Input.isfingerdown (ID))
05//Detect the finger press screen, get the current pixel coordinates, and the finger along the x, Y axis direction of displacement initialized to 0
06 {
Modified M_pixelpos = input.getscreentouchpixelposition (ID);
M_bias.x = 0.0f;
M_bias.y = 0.0f;
10}
11//Always calculate the change of the finger's displacement
if (input.isfingerpressing (ID))
13 {
Vector2 temp = input.getscreentouchpixelposition (ID);
M_bias = Temp-m_pixelpos;}
16//Detect finger lift, change the displacement to zero.
if (Input.isfingerup (ID))
18 {
Vector2 temp = input.getscreentouchpixelposition (ID);
M_bias = Temp-m_pixelpos;
M_pixelpos.x = 0.0f;
M_pixelpos.y = 0.0f;}
23}
24}
25}