I am making a 2D RPG in XNA, and I want to be able to have basic cutscenes, kinda like those in the handheld Pokemon games.

What is the easiest way to do this? Sorry for the vagueness of my question, but I'm new to game development, and nothing I've found says how to do this.

  • 6
    \$\begingroup\$ Ignore player input, do stuff, give player input back. \$\endgroup\$
    – API-Beast
    Jun 21 '12 at 21:10
  • \$\begingroup\$ "do stuff" wow that really helps! What I really want is to know how to do timing and stuff like that. An simple example would be helpful. \$\endgroup\$
    – rshea0
    Jun 21 '12 at 21:13
  • 1
    \$\begingroup\$ Do the stuff you want to show in the cutscene, that can be anything, like moving the character or displaying a text. \$\endgroup\$
    – API-Beast
    Jun 21 '12 at 21:32
  • \$\begingroup\$ By all means do NOT ignore player input! Some players dislike cutscenes and just want to whack the spacebar to skip them :) \$\endgroup\$
    – Tim Holt
    Jun 28 '12 at 16:05

For in-game cutscenes scripting is usally used.

Take a look at Luainterface. The basic idea is that you expose functionality to Lua, and then use that to create cutscenes.

Here's a super basic sample where the camera moves over to a character, and then starts a script.


lua = ScriptManager.createLua();
this.luafile = luafile;
lua.DoFile("scripts/" + luafile + ".lua");

lua.RegisterFunction("MoveCamera", this, GetType().GetMethod("MoveCamera"));
lua.RegisterFunction("SpawnChat", this, GetType().GetMethod("SpawnChat"));



function runScript()
    --pan camera to x100 and y 100 
    MoveCamera(x, y, CameraComplete); --last parameter is an onComplete function

function CameraComplete()
    SpawnChat("this is our hero ryan, isn't her handsome?");

Be sure to also check out Godpatterns: Scripting with Lua in C#

  • 2
    \$\begingroup\$ How is using a scripting language inside an XNA game an answer to creating cutscenes? \$\endgroup\$
    – Wouter
    Jun 29 '12 at 9:21
  • \$\begingroup\$ It's more about exposing methods to an external source in order to create the cutscenes. Scripting just happends to be the easiest way to do this. \$\endgroup\$
    – omgnoseat
    Jun 30 '12 at 1:14

An easy way would be to keyframe objects in the scene using a basic keyframe data structure which can then be serialized to file (xml just a few lines of C#) and opened in a custom scene editor or edited by hand.

Replay should be very straight-forward -just deserialize the file and loop through the objects, showing and moving them whenever the keyframe timestamps passes the current cut scene time. Increase the current cut scene time using the game time. This way the cut scene can easily be scrubbed back and fourth, automatically paused and it's very easy to implement various kick-ass interpolation algorithms between keyframes.

class CutScene
    List<ScriptableObject> Objects;
    TimeSpan SceneLength;
    TimeSpan CurrentPosition;

// Anything that should show up, disappear, move or otherwise
// be scripted in the scene, like NPCs, text bubbles, other sprites, camera position
class ScriptableObject
    List<Keyframe> Keyframes;

class Keyframe
    TimeSpan TimeFromSceneStart;
    Vector2 Position;
    int Rotation;

With such a basic setup, multiple cut scenes could be played back at any time and also made to overlap. There are of course several ways to attach keyframes to in-game objects/classes...


I would create a class with multiple stages the progression to the next stage would dependant on a number of events occurring

pseudo code

stage 1:
//NPC1 starts talking

show text dialog();

 _stage = 2;

stage 2:
//NPC1 walks to desk

npc.pos = MathHelper.Lerp(startpos,endpos,time/totaltime)

if(npc.pos = endpos)
_stage = 3;


I have never used Lua so do not know if that option would be better, but this is how i would do it in pure C#.


You could use timing and use your input classes.


int runTime = 0;
Control.Input = null;
curTime = DateTime.Now;
while( runTime <  5000 ) {
  if( runTime < 1000 ) {
    Control.Target = NpcStore[0];
    NpcStore[0].Say("I'm moving");
  if( runTime > 1000 && runTime < 4000 ) {
    NpcStore[0].Say("I stopped!");
  if( runTime > 4000 ) {
    NpcStore[0].Say("Cutscene ends soon.");
  runTime = (DateTime.Now - curTime).MilliSeconds;
Control.Target = PlayerCharacter;
Control.Input = Keyboard;

If it's a "simple" project without modding capabilities, including a scripting engine is often overkill.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.