Hi, Could I setup my game auto detect LANDSCAPE_RIGHT and LANDSCAPE_LEFT, instead of fixed orientation by using Application:setOrientation(orientation)
Doesn't turning on Autorotation work for you? On IOS it is basically a must that you support the opposite direction as well. Not sure about Android 3.x or 4.x, but in 2.x you only have portrait and landscape there.
The problem is that I don't know how to get device orientation with Gideros api. I set my app to LANDSCAPE_RIGHT by call application:setOrientation(LANDSCAPE_RIGHT). So, when user turns around the device, the application did not auto rotate to LANDSCAPE_LEFT.
As an addition to @MikeHart's post: When you right click the project name and select Properties..., there is a tab "iOS". From there, you can enable autorotation. Then, the screen will autorotate and there will be no difference between LANDSCAPE_LEFT and LANDSCAPE_RIGHT.
@alexzheng At first, I was thinking about inheriting Application class from EventDispatcher so that it can dispatch all system related events from a single point. But then I realized that it's not a good idea because a single point of event registering mechanism can prevent GC of objects. Therefore these kinds of events should be broadcast events, which means that it is dispatched by all EventDispatcher objects with a listener registered for this event.
(Currently, APPLICATION_START, APPLICATION_EXIT, APPLICATION_SUSPEND and APPLICATION_RESUME are broadcast events and ORIENTATION_CHANGE will be a broadcast event also)
Then ,will broadcast events be available in our lua code and plugin? For example,dispatch a broadcast event from lua or plugin code, and any object in lua can handle this event.
Thanks for so fast reply. BTW,which object do you use for broadcasting these events such as APPLICATION_START, can I broadcast an event without creating an EventDispatcher based class in plugin?
I do not mean the listener. I mean the dispatcher, is there a simple way for dispatch or broadcast an event from plugin without reference an instance of a custom EventDispatcher based class?
Using this it is quite easy to allow an app to rearrange itself and support both portrait and landscape arrangements.
I'm not sure whether this is what the OP wanted to do or whether they just wanted to get hold of the current orientation. If it's the latter you can just make use of the function BhAutoRotation:getGenericOrientation().
Comments
I don't understand clearly your explain.
The problem is that I don't know how to get device orientation with Gideros api. I set my app to LANDSCAPE_RIGHT by call application:setOrientation(LANDSCAPE_RIGHT). So, when user turns around the device, the application did not auto rotate to LANDSCAPE_LEFT.
Regards,
As an addition to @MikeHart's post:
When you right click the project name and select Properties..., there is a tab "iOS". From there, you can enable autorotation. Then, the screen will autorotate and there will be no difference between LANDSCAPE_LEFT and LANDSCAPE_RIGHT.
There is Application:getOrientation() to detect the current orientation.
Currently there is no way to get device orientation except for using some accelerometer trick.
Likes: luyimoon
https://sites.google.com/site/xraystudiogame
@alexzheng At first, I was thinking about inheriting Application class from EventDispatcher so that it can dispatch all system related events from a single point. But then I realized that it's not a good idea because a single point of event registering mechanism can prevent GC of objects. Therefore these kinds of events should be broadcast events, which means that it is dispatched by all EventDispatcher objects with a listener registered for this event.
(Currently, APPLICATION_START, APPLICATION_EXIT, APPLICATION_SUSPEND and APPLICATION_RESUME are broadcast events and ORIENTATION_CHANGE will be a broadcast event also)
For example,dispatch a broadcast event from lua or plugin code, and any object in lua can handle this event.
https://sites.google.com/site/xraystudiogame
BTW,which object do you use for broadcasting these events such as APPLICATION_START,
can I broadcast an event without creating an EventDispatcher based class in plugin?
https://sites.google.com/site/xraystudiogame
I mean the dispatcher, is there a simple way for dispatch or broadcast an event from plugin without reference an instance of a custom EventDispatcher based class?
https://sites.google.com/site/xraystudiogame
You might be interested in a little helper class that I've written to manage autorotation. There's a blog article about it here:
http://www.bowerhaus.eu/blog/files/multiple_device_orientations.html
Using this it is quite easy to allow an app to rearrange itself and support both portrait and landscape arrangements.
I'm not sure whether this is what the OP wanted to do or whether they just wanted to get hold of the current orientation. If it's the latter you can just make use of the function BhAutoRotation:getGenericOrientation().
As usual it's MIT licensed so use as you wish.
Best regards
Likes: atilim
---------------------------------------