how Change Orientation works

Hello,

i am facing problem in understanding the working of the Orientation function especially the highlighted line. its coding of Sample project “Fishies”.

Here’s the function .

local backgroundOrientation = function( event )
    – TODO: This requires some setup, i.e. the landscape needs to be centered
    – Need to add a centering operation.  For now, the position is hard coded
    local delta = event.delta
    if ( delta ~= 0 ) then
        local rotateParams = { rotation=-delta, time=1000, delta=true }

        if ( delta == 90 or delta == -90 ) then
            local src = background

            – toggle background to refer to correct dst
            background = ( backgroundLandscape == background and backgroundPortrait ) or backgroundLandscape
            background.rotation = src.rotation
            transition.dissolve( src, background )
            transition.to( src, rotateParams )
        else
            assert( 180 == delta or -180 == delta )
        end

        transition.to( background, rotateParams )

        audio.play( soundID )            – play preloaded sound file
    end
end

Basically Lua allows in-line conditional statements so you don’t have to write IF-THEN-ELSE blocks.

background = ( backgroundLandscape == background and backgroundPortrait ) or backgroundLandscape

The first thing is it asks:  Is the current background variable/table/object equal to our backgroundLandscape object. We created two different backgrounds further up in the code and assigned one to the current background. The second test after the and is to make sure the object backgroundPortrait exists or not. If so, background gets assigned backgroundPortrait if not get gets assigned backgroundLandscape. It acts like a toggle between the two.

Rob

Basically Lua allows in-line conditional statements so you don’t have to write IF-THEN-ELSE blocks.

background = ( backgroundLandscape == background and backgroundPortrait ) or backgroundLandscape

The first thing is it asks:  Is the current background variable/table/object equal to our backgroundLandscape object. We created two different backgrounds further up in the code and assigned one to the current background. The second test after the and is to make sure the object backgroundPortrait exists or not. If so, background gets assigned backgroundPortrait if not get gets assigned backgroundLandscape. It acts like a toggle between the two.

Rob