Tuesday, January 28, 2025
spot_img

Subject with DEVICEMOTION – Cocos Creator


Hello, I’m utilizing DEVICEMOTION with v2.0.10 CC venture. I exploit the next code, nonetheless the node I’m attempting to maneuver with devicemotion is unresponsive when examined on a cellular system with tilt.

cc.systemEvent.setAccelerometerEnabled(true);
cc.systemEvent.on(cc.SystemEvent.EventType.DEVICEMOTION, this.onDeviceMotionEvent, this);

 onDeviceMotionEvent: operate (occasion) {
        occasion.acc.x = this.ballAccel.x;
        occasion.acc.y = this.ballAccel.y; 
        cc.log(occasion.acc.x + "   " + occasion.acc.y);
    },

Despite the fact that occasion.acc.x and .y don’t equal 0, the code doesn’t work appropriately.

You possibly can discuss with the instance instances which have been created by new a venture, click on Examples tab . After creation, the DeviceMotion instance is beneath asset->cases->03_gameplay->01_player_control->DeviceMotion

Truly it is best to alter the goal motion on the replace operate.

I’ve the motion adjusted within the replace operate with the code

replace (dt) {
        this.node.x += this.ballAccel.y * dt * this.velocity;
        this.node.y += this.ballAccel.x * dt * this.velocity;
    },

The place this.ballAccel is a cc.v2, and this.velocity is only a single integer. The ball node strikes, however shouldn’t be taking devicemotion enter. I’ve tried to only do
this.node.x += this.ballAccel.y;, nonetheless the problem persists.

Have you ever checked the instance I listing within the beneath.

Sure. I’ve examined this on a number of cellular units and have gotten it to work prior to now, so I’m perplexed why it doesn’t now. I additionally examined the instance’s DeviceMotionCtrl code in each v2.0.10 and v1.10 which I migrated from earlier.

So I consider I discovered the problem. DEVICEMOTION occasions require the person to be prompted for permission to make use of their system’s accelerometer in iOS 13 and later. I’m utilizing a model that was launched earlier than then. Hopefully, newer 2.x variations of Cocos Creator that have been launched after iOS 13 help doing this natively. V2.2 was the primary of those it appears, though I’m not completely certain.

Upgraded my venture to v2.2. My query is, nonetheless, how do I implement the devicemotion permissions? I don’t see any means to do that outlined within the documentation for Cocos Creator. Once I run my scene within the browser, the console merely says that devicemotion permission has been denied with none dialogue field or button showing to request it. Utilizing the code cc.SystemEvent.EventType.DEVICEMOTION.requestPermission(); solely yields a kind error. Would you know the way to perform this?

Two components:
1.some browsers perhaps dont help
2.the cellphone cant help the operate

Yeah I don’t know at this level if DeviceMotion occasions can be utilized nonetheless on Cocos Creator v2.x. DeviceMotionEvent.requestPermission shouldn’t be supported, so that you’ll get an error message

I see. Possibly the v8 replace from 1.x to 2.x whereas the help for DEVICEMOTION within the V8 engine has additionally modified.

Have you ever tried the latest Model of Cocos?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles