A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: [Help] RPG Cutscenes at Runtime

Hybrid View

  1. #1
    Senior Member
    Join Date
    Aug 2004
    Location
    San Diego, California
    Posts
    421

    [Help] RPG Cutscenes at Runtime

    I don't know if anyone here as ever done something like this, but I really need some ideas and suggestions.

    Basically I want to know what would be the best way to embed cutscene elements (basic sprite movement, music transitions, dialogue, etc) into a text file. How would I go about formatting these elements so that when Flash reads the text file, it is able to recreate the cutscene at runtime as opposed to me having to create them through motion tweening and animation. Any suggestions?

  2. #2
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    Well, I suppose you could format it a bit like this (make sure you know how to use the String.split() function extremely well, though):

    1|1x1250,3x500|{1:100,100}/{2:300,200}/{5:400,300}

    I'll translate it.

    The 1 at the start is the background chosen. You'd make it load a background from the library by attaching "backGround"+bgdNumber. The number shown here would be the bgdNumber variable. The | ends the background segment, and now you move onto the music segment:

    1x1250,3x500

    This means it would play sound track 1, and stop it after it's been running for 1,250 milliseconds, then move onto the thing you've typed after the comma. In this case, it means play sound track 3 for 500 milliseconds. The same thing could be done with backgrounds, but then you'd also have to set it up so that the sprites would move when the background changes. Now we move to the sprite initialiser segment of the string, since we've hit another | symbol.

    {1:100,100}/{2:300,200}/{5:400,300}

    Between the first curly brackets it says 'Place sprite 1 at the coordinates 100,100'. If need be, you could also tell it to give him other properties, such as _xscale and _yscale. The / tells it to create another sprite. The sprite number will help the script identify which sprite to pick out from the library, such as "sprite"+spriteNumber.

    So that's a basic way in which you could implement it. For dialogue, you could add something like this on the end of the example text I wrote:

    |26*"Hello World!"*80/90*"Hello to you, too."*150|

    This would mean that after 26 frames has passed (or you could use getTimer() and make it in terms of milliseconds passing, which would help it sync up with the music), a subtitle saying "Hello World!" would appear, and after 80 frames, it would disappear again. You could change it so that it made a speech bubble instead of a subtitle, but then you'd need to specify coordinates and sizes for the bubbles and stuff. Note that I use a * symbol to separate the parameters in that string, since it's likely you'll be using a comma in the dialogue quite often. I also use a / to separate the two subtitles used, but that's only for readability - you would treat it the same way as a * symbol, or use a * symbol instead of it anyway.

    Sprite movements would be implented in a similar way. You would tell which sprite to be in which stances at which times, which way they're facing (could be part of a stance anyway, though), what coordinates they're moving to, how quickly, etc.

    You'd need to make Flash be able to read these strings and decode the mess of numbers and symbols to make the final product, though. It's up to you how you make that happen, but I'd look into the split, indexOf, toString, and Number() functions (and other things if you want to go a bit further with it).

    Hope this helps!
    http://www.birchlabs.co.uk/
    You know you want to.

  3. #3
    Senior Member
    Join Date
    Aug 2004
    Location
    San Diego, California
    Posts
    421
    Thanks VENGEANCE MX!

    That looks like an efficient and simple way of formatting the scenes. At first I was thinking of using xml files, but I figured that parsing the file would be too much of job for Flash not to mention the file size. But I think your format would work just fine because the seperate parts of the cut scenes are seperated by delimiters as opposed to tags so file size won't be that much of an issue. Now I just have to build an editor that would output these strings.

    Oh, another thing. How could I modify your format so that instead of being time based, the transitions are triggered by key presses. For example, when there is a dialogue in progress, the game waits for user input before it moves to the next part of the scene. Thanks again, that helped!

  4. #4
    my x booty it is that BIG
    Join Date
    Jun 2004
    Location
    New York
    Posts
    696
    wow MX really good stuff here
    Project||[GAME]-on hold for now
    ------------------
    [Hero]-80%
    [Enemies]-1%
    [Weapons]-90%
    [Items]-0%
    [Levels]-10%

  5. #5
    hmm Pugger's Avatar
    Join Date
    Sep 2003
    Location
    Perth, Australia
    Posts
    616
    I don't think XML is that slow to process. It is far more readable than a textfile, as well as flexible. Even with XML, I doubt filesize will get out of hand, unless you were thinking of having one XML file for the WHOLE game, which would be overkill. It would make sense to split it up, calling on the XML file when needed.

    About keypresses, thats fairly easy to solve. Just don't have the timers. Using Vengeance MX's line:

    |26*"Hello World!"*80/90*"Hello to you, too."*150|

    Just change it to something like:

    |"Hello World!","Hello to you, too."|

    And goto the next string on keypress.

  6. #6
    Untitled-2.fla
    Join Date
    Jul 2002
    Posts
    391
    the problem VENGEANCE has created is writing in what is essentially machine code something that the user has to create, why not simply write it in a symantic may (human terms), to that it's easy to write, scannable (makes sence to you) and just as easy to parse .... and the best way to do this is with a structured format i.e. XML

  7. #7
    Senior Member
    Join Date
    Aug 2004
    Location
    San Diego, California
    Posts
    421
    Quote Originally Posted by token 3
    the problem VENGEANCE has created is writing in what is essentially machine code something that the user has to create, why not simply write it in a symantic may (human terms), to that it's easy to write, scannable (makes sence to you) and just as easy to parse .... and the best way to do this is with a structured format i.e. XML
    But if I am going a write an editor, writing a method that would output the code along with tags (both open and closed tags) would be tedious in my opinion.

    After giving some thought into Vengeance's code, I realized that decoding it (String.split, indexOf, etc) would also be too tedious, so why not use &varName=value format instead and use loadVars() to read in the variables. This way, like you mentioned token, it would be somewhat more readable, but at the same time easier to read in to Flash and decode it so something in between vengeances method and XML.

  8. #8
    skylogic.ca MD004's Avatar
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    366
    You could do it similar to the way I did my game which I know you've looked at already but I'll paste some parts here anyway, and it also happens to be the same concept as VENGEANCE's idea btw. Here's what i've done:

    event1[180] = [600,150, "2", 2, "delete", [-50,150], [-50,235], [600,235]];
    event1[220] = [0,330, "2", 2, "delete", [650,330], [650,240], [0,240]];


    in the case of my game, this creates one enemy at x600 y150 and the other parameters are waypoints and stuff. To get to flash to use it I use this:

    time++;

    if (_root["event"+currentLevel][time]!=null) {
    . duplicateEnemies.apply(this, event1[time]);
    }


    where duplicateEnemies is the following function and event1[time] is the parameters for the function, so when the time==180 (my first example above) then it creates the enemy.

    function duplicateEnemies(x, y, enemyType, actionWaypoint, action, w0, w1, w2, w3, w4, w5, w6, w7, w8, w9) {
    ...
    }


    So to make this work for you, you could something like this:

    sprite[1] = [100, 200, "superHeroDude", "mainChar");
    movement[30] = [400, 120, "mainChar"];
    sound[1] = ["walking", start];
    sound[30] = ["walking", stop];


    Where 'mainChar' is an instance name and superHeroDude is the symbol in the library, the rest are easy to figure out i think. Then you would have something like this: (i took away the if statement that was in my example, but if you do this than I think you should include it)

    time++;

    addSprite.apply(this, sprite[time]); //by the way, _root could also work instead of 'this'
    moveSprite.apply(this, movement[time]);
    manageSound.apply(this, sound[time]);

    ...

    function addSprite(x, y, symbolName, instanceName) {
    attachMovie...
    ..._x = x;
    etc
    }

    function moveSprite(x, y, instanceName) {
    if (..._x < x) { ...._x += speed; } //I suppose speed would be a good parameter to add
    }


    but of course for movement you would have to get a little creative, because you want the function to keep being called, I'd probably use setInterval() for that. Also, the variables (such as sprite[1]=[...]) could be loaded from the text file instead of hardcoded into the game like mine...hey that gives me an idea, I could load my levels from a text file! why didn't i think of that before -that's what I love about forums, ideas get shared

    Anyway, I think you get the idea, good luck

    ~MD

  9. #9
    hmm Pugger's Avatar
    Join Date
    Sep 2003
    Location
    Perth, Australia
    Posts
    616
    Quote Originally Posted by andross_88
    But if I am going a write an editor, writing a method that would output the code along with tags (both open and closed tags) would be tedious in my opinion.
    As tedious as outputing text, honestly I see text being a harder option. You can create an XML object in flash, add your elements to that, and output that as a string (you then copy and paste into an .xml doc). Flash does all the tags for you if you do that - you just have to structure it efficiently.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center