0

I've been playing around with mobile game dev using Cocos Creator, which is built on top of Cocos2d-JS. The question is, how can we detect a change in orientation in the game app in Android using Javascript?

The 'window' and 'document' element is not available, and there is no orientation change events. I tried to detect the change using screen size instead via cc.view.getFrameSize(), which should be equivalent to getting the canvas size(view port). I started off with getting {width:2560, height:1440} at landscape mode.

But when I rotated the device to portrait mode, cc.view.getFrameSize() was still returning me {width:2560, height:1440}. However, using adb logcat I could see events below:

> 09-29 19:24:50.151 3449 3449 V WindowOrientationListener:
> OrientationSensorJudge.onSContextChanged, Rotation: 0 09-29
> 19:24:50.161 3449 3526 V WindowOrientationListener:
> OrientationSensorJudge.getProposedRotation, Rotation: 0 09-29
> 19:24:50.161 3449 3526 V WindowManager:
> rotationForOrientationLw(orient=4, last=1); user=0 sensorRotation=0
> mLidState=-1 mDockMode=0 mHdmiPlugged=false
> mMobileKeyboardEnabled=false displayId=0 09-29 19:24:50.161 3449 3526
> V WindowOrientationListener:
> OrientationSensorJudge.getProposedRotation, Rotation: 0 09-29
> 19:24:50.161 3449 3526 D SamsungWindowManager: setRotationLw() :
> rotation=0 09-29 19:24:50.201 3449 3965 I InputReader: Reconfiguring
> input devices. changes=0x00000004 09-29 19:24:50.201 3449 3965 I
> InputReader: Device reconfigured: id=4, name='sec_touchscreen', **size
> 1440x2560,** orientation 0, mode 1, display id 0

The size has changed to 1440x2560 instead. But the frame returned from the function isn't changing. :(

Any tips on how to solve this? I have not tried for iOS yet, but any points on how to do it on iOS also will be appreciated!

Thanks.

evkwan
  • 693
  • 3
  • 9
  • 17

1 Answers1

0

After digging around in the Cocos2d Forum for a bit, this thread suggests that there is no way to detect orientation change happening in the phone yet. One can only lock the orientation in native at the start for now, and programatically change the orientation if required.

evkwan
  • 693
  • 3
  • 9
  • 17