【问题标题】:Adding background at certain part在特定部分添加背景
【发布时间】:2016-02-08 16:43:13
【问题描述】:

我正在更新我的文本冒险引擎并想为故事的每个部分添加背景。目前的问题是让背景出现在它们各自的部分。

public var parts:Object = 
{

    "0":
        {
            "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.",
            "choices":
                {
                    "response1":
                        {
                            "text":"Investigate",
                            "nextPart":"1"
                        },
                    "response2":
                        {
                            "text":"Ignore it. You need your beauty sleep.",
                            "nextPart":"2"
                        }

                },
        },

我会添加什么,以便我可以在每个部分显示背景。

这是我目前拥有的背景(在部分之后定义)

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

【问题讨论】:

    标签: arrays actionscript-3


    【解决方案1】:

    由于您嵌入了背景图像和“部件”数据结构,因此您可以简单地在 parts 对象中引用您的背景类:

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

    然后在您将游戏更新到某个“部分”的代码中,显示该部分引用的背景:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-18
      • 1970-01-01
      相关资源
      最近更新 更多