Cineractive Tutorial
Unlike Armada 1, Armada 2 does not use full screen videos. Instead it uses a special view on the standard 3D world, called Cineractives. The Cineractive library lets you create and control these sequences and this tutorial will go through the creation of a simple cineractive sequence.
The Plan
Here's what we will do in our simple cineractive sequence, which is a fairly standard introduction. Our introduction will feature a ship approaching a station.
- Fade from black
- Show title and subtitle
- Look from station at ship as it approaches
- Fade out title and subtitle
- Fade to black
Entering Cineractive Mode
Before any Cineractive functions will work, we need to enter Cineractive mode. To do this, we must active it using the active property. Adding the following code to the setup function will do this.
Cineractive.active = true
Fading in Screen and Titles
Our first step is to fade in from black and to show the title and subtitle. Although not technically part of the Cineractive library, the functions for titles and subtitles are often used in Cineractives, so have been used here. Add the following code to the setup function.
--Screen will fade in over two seconds
Cineractive:fadeIn( 2.0 )
--Add the title at coordinates 50, 50. It will fade in, stay and fade out over four seconds
UI:addTitle( "Cineractive Tutorial", 50, 50, 4.0, true )
--Add subtitle below the title. It will stay the same amount of time as the title
UI:addSubtitle( "The Flyby", 50, 75, 4.0, true )
Look from the Station
The station we want to look from has the label sfc, so we just need to look for that using an EntityFinder. Since we want to look from above and to the right of the station we must set a camera offset. The following code does this and should be added to the setup function:
--Search for entities that have the "sfc" label. Since there is only one
--we will get the station
local sfc = EntityFinder( function(e)
return e:isType(Entity.Type.GameObject)
and e.label == "sfc"
end ):findOne()
Cineractive:lookFrom( sfc )
--200, 100, 0 is slightly above and to the right of the station
Cineractive:setCameraOffset( Vector( 200, 100, 0 ) )
Look at the Ship
Looking at the ship is quite a similar process to looking at the station. We search for an entity with the fedship label and then tell the Cineractive library to look at it. We also set the ship moving towards the station. Adding the following code to the setup function will do this.
--Search for entities that have the "fedship" label. Since there is only one
--we will get the ship
local ship = EntityFinder( function(e)
return e:isType(Entity.Type.GameObject)
and e.label == "fedship"
end ):findOne()
Cineractive:lookAt( ship )
ship:giveOrder( GameObject.Order.Go, sfc )
Fading out Screen and Titles
We want the screen to start fading to black once the ship has arrived at the station. To do this we are going to use a timer that ticks after 23 seconds (this is about how long it takes for the ship to stop at the station). This code should be added at the bottom of setup.
--This timer will go off in 23 seconds (about the time it takes for the
--ship to reach the station).
local fadeTimer = Timer( "fadeTimer", 23, Timer.State.Started )
--Hook function will fade the screen out over two seconds
fadeTimer:hook( "fadeOut", nil, function(timer, hook)
Cineractive:fadeOut( 2.0 )
end, nil )
Ending the Cineractive
Once the screen has faded we want to end the Cineractive and return control to the player. To do this we just set Cineractive.active to false. We also center the camera on the station.
--This time will go off in 26 seconds (this will be after the screen has faded
--out)
local endCineractiveTimer = Timer( "endTimer", 26, Timer.State.Started )
--Hook function will end the Cineractive and focus the camera on the station
endCineractiveTimer:hook( "endCineractive", nil, function(timer, hook)
Cineractive.active = false
Camera.center( sfc )
end, nil )
Finished Script
Here's the final script for the mission.
class 'CineractiveTutorial'
function CineractiveTutorial:__init( )
end
function CineractiveTutorial:setup( )
Cineractive.active = true
--Screen will fade in over two seconds
Cineractive:fadeIn( 2.0 )
--Add the title at coordinates 50, 50. It will fade in, stay and fade out over four seconds
UI:addTitle( "Cineractive Tutorial", 50, 50, 4.0, true )
--Add subtitle below the title. It will stay the same amount of time as the title
UI:addSubtitle( "The Flyby", 50, 75, 4.0, true )
--Search for entities that have the "sfc" label. Since there is only one
--we will get the station
local sfc = EntityFinder( function(e)
return e:isType(Entity.Type.GameObject)
and e.label == "sfc"
end ):findOne()
Cineractive:lookFrom( sfc )
--200, 100, 0 is slightly above and to the right of the station
Cineractive:setCameraOffset( Vector( 200, 100, 0 ) )
--Search for entities that have the "fedship" label. Since there is only one
--we will get the ship
local ship = EntityFinder( function(e)
return e:isType(Entity.Type.GameObject)
and e.label == "fedship"
end ):findOne()
Cineractive:lookAt( ship )
ship:giveOrder( GameObject.Order.Go, sfc )
--This timer will go off in 23 seconds (about the time it takes for the
--ship to reach the station).
local fadeTimer = Timer( "fadeTimer", 23, Timer.State.Started )
--Hook function will fade the screen out over two seconds
fadeTimer:hook( "fadeOut", nil, function(timer, hook)
Cineractive:fadeOut( 2.0 )
end, nil )
--This time will go off in 26 seconds (this will be after the screen has faded
--out)
local endCineractiveTimer = Timer( "endTimer", 26, Timer.State.Started )
--Hook function will end the Cineractive and focus the camera on the station
endCineractiveTimer:hook( "endCineractive", nil, function(timer, hook)
Cineractive.active = false
Camera.center( sfc )
Objectives:load("CineractiveTutorialObjectives.txt" )
Objectives.visible = true
end, nil )
end
MMM.register( CineractiveTutorial( ) )