The coocs2d-html5 calls the device's accelerometer when using cocoseditor to use gravity sensing

Source: Internet
Author: User

In the use of Daniel touchsnow development plug-in cocoseditor game development encountered some problems, and then try to solve, recently want to try the coocs2d-html5 can use gravity sensing, found that is OK, however, this can only be tested on a mobile real machine, but not on a computer simulator,

You must first set the Accelerometer in the onDidloadFromCCB () method:

This. rootNode. onAccelerometer = function (event) {this. controller. onAccelerometer (event) ;}; cc. log ("sys. OS: "+ sys. OS); if (sys. OS = "android" | sys. OS = "ios") {this. rootNode. setAccelerometerEnabled (true);} // then rewrite onAccelerometer (); Method MainLayer. prototype. onAccelerometer = function (event) {cc. log ("event: x. "+ event. x + "; y. "+ event. y + "; z. "+ event. z );}


In this way, the accelerator can be used,
X, y, and z coordinates can be output after real machine testing. OK

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.