- In conf.lua, add c.accelerometerjoystick = true (or t. if you use t instead of c).
- Require the library with: local portland = require 'portland'
- At initialization, define the tweening function to use for the rotation and the duration of the rotation, using portland.setTween(easing_function, duration_in_seconds). If easing_function is false, the change is immediate (default). portland includes a few built-in easing functions, I recommend sigmoid5 or brake:
- On love.update, call portland.updateOrientation(dt).
- At the top of love.draw, call portland.orient(). Note it fiddles with the Löve transform, so if you call love.graphics.origin(), call portland.orient() again afterwards before drawing to the screen.
- In your program, use portland.width and portland.height to read the current width and height in real time, and use them to adjust the visualization as required. The included example program uses them to scale an image so that the aspect ratio is preserved. If you need the current orientation, the property portland.orientation tells you, but note that it's the target value of the tweening and is not updated during the tweening. If you want one that is updated during tweening, use portland.angle instead.
- portland.physWidth, portland.physHeight: The physical width and height of the screen as returned by love.graphics.getWidth() and .getHeight() respectively. Useful to not be calling these functions repeatedly.
- portland.stableTime: The time in seconds for the current orientation to be considered stable and change to it. Defaults to 0.4.
- portland.forceOrient(n): Forces a specific orientation regardless of the accelerometer values. 0 is landscape, 90 is portrait, 180 is landscape inverted, 270 is portrait inverted, false means stop forcing an orientation.
- portland.onOrientationChange: It's a callback you may define when you want to be notified about a change in orientation. The parameters are the target orientation, the target width and the target height.
Sorry, no github. This was a pet project and I didn't use source control.
Here it is. Enjoy!