Forced Orientation

Hey guys! I hope this is an easy question to answer. Is there a way to change the orientation in the middle of a game? For example, if I’m in landscape mode, and there’s some button that sets supportedOrientations(PORTRAIT) I can still stay in landscape mode until I feel like turning my iPad. So is there a way to force-change orientation without waiting for the player?

To force change orientation, you might have to do it manually, with a rotate command at the root level of your drawing. Although when the player did eventually turn their pad, you’d have to catch that with the orientationChange function and switch off the manual rotate.

It ain’t pretty (mainly because orientationChanged doesn’t fire until after the built in animation has completed) but it seems to be what you’re describing. Edit V2 update the centre point when the orientation changes:

-- Orientation Switch
supportedOrientations(LANDSCAPE_LEFT)
displayMode(OVERLAY)

function setup()
    orient = {game=0, device=LANDSCAPE_LEFT} --game= orientation of game world, in degrees. 
    --device = orientation of device, LANDSCAPE_LEFT (=2), PORTRAIT (=0)
    parameter.action("force portrait", function() forceOrientation(PORTRAIT, -90) end)
    parameter.action("force landscape", function() forceOrientation(LANDSCAPE_LEFT, 90) end)

    fill(0, 255, 122, 255)
    fontSize(200)
    textAlign(CENTER)
    centre = vec2(WIDTH, HEIGHT) * 0.5 --centre point around which we rotate
end

function draw()
    background(40, 40, 50)
    translate(centre.x, centre.y) --rotate around screen centre
    rotate(orient.game)
    translate(-centre.x, -centre.y)
    --drawing here
    text("HELLO\
WORLD!!!", WIDTH * 0.5, HEIGHT * 0.5)
end

local rotSpeed = 0.2 --speed of animation, meant to mimic the built-in anim

function forceOrientation(device, game)
    if orient.device==device then --if already in the required orientation
        tween(rotSpeed,orient, {game = 0}) --cancel manual rotate
    else
        tween(rotSpeed,orient, {game = game}) --manual forced rotate
    end
    supportedOrientations(device)
end

function orientationChanged(o)
   -- sound(SOUND_BLIT, 20863)
    tween(rotSpeed, orient, {game = 0}) --cancel out manual rotate
    centre = vec2(WIDTH, HEIGHT) * 0.5 --redefine centre
    orient.device = o --remember orientation
end

Updated the above code to catch instances where the device is already in the orientation you’re wanting to force

Thanks @yojimbo2000! That’s pretty cool! A slightly more pretty, but slightly more complicated solution would be to have a screen telling you to rotate the device, and pause the game until you do