Workaround for Physics gravity direction not adjusting when rotating device


(www.360FUN.net) #1

Hi @jonathan, I’ve the 90° problem in landscape mode: I need to have the gravity always at the bottom to simulate things falling…any workaround? Would be nice in the future to have an option about this. Thanks! :smile:


Cannot control the gravity with device tilt in an iBook on an iPad
(Lucky) #2

Would having 2 layouts, one portrait , one for landscape with gravity direction changed on those work?


(www.360FUN.net) #3

Yes, but how? Hype manages different screen sizes, but it doesn’t base the decision to show a layout or another in relation of the landscape or portrait mode…if I got it right, of course. It means, you can have a 1024px screen because you’re in a desktop computer (always portrait) or in an iPad in landscape mode, so you cannot be sure, you need to detect it from the accelerometer (event.orientation).

I had in mind something like this:

But if is possible to do it natively, even better! :smile:


(www.360FUN.net) #4

anybody? @Daniel?


#5

That’s true: Though this appears like a ‘portrait’ iPad, it’s really the measurement of the width of the device (any device).

One option is to reload the scene on device rotation (which would trigger an ‘onresize’ event). This could be run ‘on scene load’ for your scene.

window.onresize = function(event) {

	// reload the current scene to reset 'gravity' 
}

(www.360FUN.net) #6

It doesn’t work…it reloads the scene but the gravity is still rotated by 90° :frowning: Could you send me a working example? Thanks! :wink:


#7

Here’s an example: reload-physics-on-rotate.zip (14.8 KB)

It gets the current scene, and reloads it:

var currentscene = hypeDocument.currentSceneName()

window.onresize = function(event) {
	hypeDocument.showSceneNamed(currentscene, hypeDocument.kSceneTransitionInstant)
}

(www.360FUN.net) #8

If you activate “control gravity with device tilt” it doesn’t work :frowning:


(www.360FUN.net) #9

@Daniel it doesn’t work with device tilt active, that’s what I need: if I turn the phone/tablet the gravity must turn by 90° and remain always in the bottom…


#10

Hmm sorry but I’m not sure how to resolve this. At this time Physics may need a page reload to reset the gravity directions unfortunately.


(www.360FUN.net) #11

But I cannot make your example working with tilt active…maybe I’m missing something. It works with your mobile/tablet? :confused: