The last 2 weeks or so, I’ve been working on an update for Weston Westie, and one of the things coming out with the update is cutscenes.
I’ve been integrating Squirrel Scripting into the engine, as I thought would make things easier if I used a scripting language.
After the initial painful process of making it work on Samsung Wave, creating some bindings between C++ and Squirrel, things started to pick up.
In Weston Westie, cutscenes are mostly a series of still images, playing some sounds, some fading out/in, the occasional moving background, etc.
Using coroutines, the cutscene scripting is done in a serial way, unaware of the game loop.
The scripting for this particular scene goes kind of like this (simplified version)…
function SailAway() { // Load needed resources... local imgDash = resourcemanager.Get(ResourceType.IMAGE, "Sequences_Debut_Dash"); local imgWestonOnFire = resourcemanager.Get(ResourceType.IMAGE, "Sequences_Debut_WestonOnFire"); local imgEnd1Shore = resourcemanager.Get(ResourceType.IMAGE, "Sequences_End1Shore"); local sngDetermination = resourcemanager.Get(ResourceType.SOUND, "Determination"); // ... // Create a UI Scene to use local scene = CUIScene.Create(); scene.Activate(); // Create two widgets to display a background, and a front image local back = CWidget.Create(scene.GetRootWidget()); local front = CWidget.Create(scene.GetRootWidget()); // Setup the images back.SetBackgroundImage(imgWestonOnFire, CColour4.WHITE); front.SetBackgroundImage(imgDash, CColour4.WHITE); // Setup background and foreground images movement using some helper classes // ... // // First part - Weston appearing, with the "fire" background // // play introduction song as weston appears local sngH = soundmanager.Play(sngDetermination, false); TickFor(2.0); // animate everything for 2 seconds // starts a fade out on the song, that takes 4 seconds soundmanager.SetFade(sngH, 0, 4.0); TickFor(1.0); // animate for 1.0 // // Second part - weston surprised // // Show weston surprised at shore front.SetBackgroundImage(imgEnd1Shore, CColour4.WHITE); // Play "surprised" sound soundmanager.Play(sndWhat, false); TickFor(1.0); // .. and the list goes on, serially showing images, // playing sounds, fading, etc }
My engine doesn’t have any specific support for cutscenes, or fancy editors, so each cutscene is basically handcoded.
I do have some utility code to automate a fade in/ou, or move an image around for example.
I use mostly C++, so I’m used to strongly typed languages. Using a scripting language like squirrel is a bit painful at start, as the compiler isn’t much of a help catching mistakes. On the other hand, it does force you to pay more attention on what you’re doing.
Overall, I’m happy with squirrel. The library is relatively small, and with a bit of effort you can find your way around.
In the future I’ll probably try some other scripting languages, particularly Lua, since it’s so widespread in the games industry, or AngelScript, which is not that widespread, but has a nice feature set and it’s closer to C++.