New Dialog System - Multiple Backgrounds

Started by oskargunn, Wed 17/09/2014 11:23:49

Previous topic - Next topic

oskargunn

Hi,

I am doing a GK style dialog system.
I do this by creating a special Dialog room. Each time I talk to a character both character are moved to that room, the dialog takes place with portraits of their faces and dialog options. Afterwards both character are moved to previous room.

I have more or less the implementation ready, however I would like to add a feature that I'm not sure on how to do.  Instead of having a black background in the Dialog-Room, I would like to have a faded version of the background last room visited and the portraits of the character on top of that.

I've read somewhere about setBackgroundFrame, but there's a limit of 5 frames, so maybe that is not the correct way. Does anybody have an idea on how to implement a thing like that? :)



Crimson Wizard

#1
IMHO better way is to take a screenshot before changing rooms, then paint it on the dialog room's background.

Check the manual for:
1. Dynamic sprites;
2. Drawing surfaces;
3. DynamicSprite.CreateFromScreenShot function
4. Room.GetDrawingSurfaceForBackground function

Basic code:
Code: ags

// in GlobalScript.ash
import DynamicSprite *LastRoomScreenshot;
import function MakeRoomScreenshot();
import function PaintRoomScreenshot();

// in GlobalScript.asc
DynamicSprite *LastRoomScreenshot;
export LastRoomScreenshot;

function MakeRoomScreenshot()
{
    // delete old screenshot if it exists
    if (LastRoomScreenshot != null)
        LastRoomScreenshot.Delete();

    // hide mouse cursor and make room screenshot
    mouse.Visible = false;
    Wait(1); // wait a tiny bit to let game redraw once without mouse
    LastRoomScreenshot = DynamicSprite.CreateFromScreenShot();
    mouse.Visible = true; // show mouse again
}

function PaintRoomScreenshot()
{
    if (LastRoomScreenshot == null)
        return; // no screenshot was made

    // paint screenshot over main background
    DrawingSurface *ds = Room.GetDrawingSurfaceForBackground();
    // draw image with 50% transparency
    ds.DrawImage(0, 0, LastRoomScreenshot.Graphic, 50);
    ds.Release();
}


Call MakeRoomScreenshot() before changing rooms, and PaintRoomScreenshot() on entering dialog room.

NOTE: you may also want to hide GUIs before taking screenshot; just handle this in similar way as with mouse cursor.

oskargunn

Awesome, thanks! :)
It works like a charm :)

SMF spam blocked by CleanTalk