Friday, September 18, 2015

c# - How to handle cutscenes in XNA?


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.



Answer



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#


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...