Multi-touch handling on Unity iPhone

Source: Internet
Author: User

There are a lot of questions on the unity forums about how to handle multi-touch on iPhone. we 've done a few experiments with multi-touch-although nothing in a game yet-but here's one solution. this had a few goals:

    • Avoid etoonetouchphase, Which is unreliable (maid with the remote)
    • Abstract touch tracking logic from game logic
    • Use a minimal amount of code



Multi-touch example (Unity iPhone) from Matthew Wegner on Vimeo.

This solution breaks the problem up into two classes, a tracker and a manager. The core of the Manager uses a hashtable to tie tracker objects to their finger IDs. The logic looks like:

    1. Reset All trackers to "clean" state
    2. Loop through all touch events
      1. If we don't have a tracker for this finger ID, create one (and assume touch has started)
      2. If we already have a tracker object for this finger ID, tell it to update
      3. Mark tracker as dirty
    3. Any trackers that are still marked clean are assumed to be ended

There is some logic separation here, although it isn' t as clean as it cocould be. the code that's spawning/moving cubes is placed directly into the touchtracker class. in production we wocould strive to split this up, so the grunt work of tracking touches is totally separate from any game logic. you cocould have your game logic get comprehensions of new/ended touches, Or you cocould subclass touchtracker and set up functions like ontouchstarted, ontouchended, and ontouchupdated. unity presents a lot of options for situations like this.

Enjoy the example, and comment if you make any changes or improvements. This is far from perfect, but I think it's a good direction to take.

Download multi-touch sample project

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.