Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
6  
Ignore player input, do stuff, give player input back. –  Mr. Beast Jun 21 '12 at 21:10
    
"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. –  ryansworld10 Jun 21 '12 at 21:13
1  
Do the stuff you want to show in the cutscene, that can be anything, like moving the character or displaying a text. –  Mr. Beast Jun 21 '12 at 21:32
    
By all means do NOT ignore player input! Some players dislike cutscenes and just want to whack the spacebar to skip them :) –  Tim Holt Jun 28 '12 at 16:05
add comment

4 Answers

up vote 5 down vote accepted

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.

C#

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"));

lua.GetFunction("runScript").call();

Lua

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#

share|improve this answer
2  
How is using a scripting language inside an XNA game an answer to creating cutscenes? –  Wouter Jun 29 '12 at 9:21
    
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. –  omgnoseat Jun 30 '12 at 1:14
add comment

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...

share|improve this answer
add comment

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();

if(dialogcompleted)
{
 _stage = 2;
}

stage 2:
//NPC1 walks to desk

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

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

etc

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#.

share|improve this answer
add comment

You could use timing and use your input classes.

Pseudocode:

int runTime = 0;
Control.Input = null;
curTime = DateTime.Now;
while( runTime <  5000 ) {
  if( runTime < 1000 ) {
    Control.Target = NpcStore[0];
    Control.Event(KeyPress.Left);
    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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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