Home Ask Login Register

Developers Planet

Your answer is one click away!

Badfitz66 February 2016

Adding background at certain part

I'm updating my Text Adventure engine and want to add a background for each part of the story. The problem at the moment is making the backgrounds appear for their respective part.

public var parts:Object = 

            "text":"You're name is David, a agoraphobic 24 year old. It's 12:32 AM, you were woken abruptly by glass smashing inside your house.",
                            "text":"Ignore it. You need your beauty sleep.",


What would I add so I can make a background appear at each part.

Here's the backgrounds I have currently (defined after parts)

[Embed(source = "../Backgrounds/old-bedroom.png")]
public var Background1:Class
public var Background1PNG:BitmapData 
public var BG1:Bitmap = new Background1
public var bR:Sprite = new Sprite();

[Embed(source = "../Backgrounds/img010.jpg")]
public var Background2:Class
public var Background2PNG:BitmapData 
public var BG2:Bitmap = new Background2
public var lR:Sprite = new Sprite();


Aaron February 2016

Since you are embedding your background images and your "parts" data structure, you can simply refer to your background classes in your parts object:

"0": {
    "text": "...",
    "choices": { ... },
    "background": Background1

Then in your code where you the update the game to some "part", display the background referenced by that part:

var background:Bitmap;
function updateBackground(part:Object):void {
    if (background) {
        // remove old background
    // add new background
    background = new part.background();

Post Status

Asked in February 2016
Viewed 1,231 times
Voted 13
Answered 1 times


Leave an answer

Quote of the day: live life