Genesis-3d Open source game engine Full Instance tutorial Cool game 04: Realize Touch operation

Source: Internet
Author: User
Tags touch

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}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.