Actionscript 3:将 MovieClip 放置在特定层上?

发布于 2024-11-18 04:47:42 字数 404 浏览 1 评论 0原文

我目前正在开发一款平台游戏,我有一堆不同的图块用来形成我的地图。这些瓷砖的外观差异很大,而且彼此相邻放置,变化非常剧烈,不太美观。我一直在尝试通过以下方式解决此问题:

我有四层,每个要褪色的块有两层。第一层是实际图块(图形)所在的位置。第二层是面具。在遮罩层中,我有一个渐变,它与其他图块遮罩层完全相反(遮罩层 1 向下,遮罩层 2 向上)。然而,我需要能够动态地改变这些,将新的渐变放置在适当的遮罩层中,并将新的图块放置在适当的图形层中。

我在过去一个小时左右的时间里一直在谷歌搜索,试图找到一种方法来定义新的 MovieClip 放置在哪一层,但我找到的只是 setChildIndex,因为一层充当遮罩,所以我可以不用。 Actionscript中是否有这样的功能,或者我是否要手动制作所有图块组合?

感谢您的帮助, -Birjolaxew

I am currently working on a platformer, and I have a bunch of different tiles I use to form my maps with. These tiles are very different in the looks, and placed besides eachother, they give a very sharp change, which is not very visually appealing. I've been trying to fix this in the following way:

I have four layers, two for each block I'm fading. The first layer is where the actual tile, the graphic, is located. The second layer is the mask. In the mask layer, I have a gradient, which is the exact opposite of the other tiles mask layer (Mask layer 1 goes down, mask layer 2 goes up). However, I need to be able to alter those dynamically, place new gradients in the appropriate mask layer, and new tiles in the appropriate graphics layer.

I've been googling around for the last hour or so, attempting to find a way to define which layer a new MovieClip is placed on, but all I've found is setChildIndex, which, since one layer acts as a mask, I can't use. Is there any such function in Actionscript, or am I to make all combinations of tiles by hand?

Thank you for your help,
-Birjolaxew

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月打碎记忆 2024-11-25 04:47:42

尝试使用类似此类的内容:

package
{
    import flash.display.Sprite;

    public class LayeredContainer extends Sprite
    {
        // vars
        private var _layers:Array = [];

        /**
         * Constructor
         */
        public function LayeredContainer()
        {
            createLayer("_fallback_");
        }

        /**
         * Defines the layers to use
         * @param ...layers A list of layers to add
         */
        public function createLayers(...layers):void
        {
            var i:String;
            for each(i in layers)
                createLayer(i);
        }

        /**
         * Creates a single layer, adding it to the top of the display list
         * @param id The layer id
         */
        public function createLayer(id:String):Sprite
        {
            var l:Sprite = new Sprite();
            _layers[id] = l;

            addChild(l);

            return l;
        }

        /**
         * Returns a layer based on id
         * @param id The layer to return
         */
        public function layer(id:String):Sprite
        {
            return _layers[id] || layer("_fallback_");
        }
    }
}

然后您可以创建图层并添加如下内容:

var lc:LayeredContainer = new LayeredContainer();
lc.createLayers("tiles", "whatever", "mask");

addChild(lc);

lc.layer("tiles").addChild(_some_tile_you_made_);

Try using something like this class:

package
{
    import flash.display.Sprite;

    public class LayeredContainer extends Sprite
    {
        // vars
        private var _layers:Array = [];

        /**
         * Constructor
         */
        public function LayeredContainer()
        {
            createLayer("_fallback_");
        }

        /**
         * Defines the layers to use
         * @param ...layers A list of layers to add
         */
        public function createLayers(...layers):void
        {
            var i:String;
            for each(i in layers)
                createLayer(i);
        }

        /**
         * Creates a single layer, adding it to the top of the display list
         * @param id The layer id
         */
        public function createLayer(id:String):Sprite
        {
            var l:Sprite = new Sprite();
            _layers[id] = l;

            addChild(l);

            return l;
        }

        /**
         * Returns a layer based on id
         * @param id The layer to return
         */
        public function layer(id:String):Sprite
        {
            return _layers[id] || layer("_fallback_");
        }
    }
}

Then you can create your layers and add things like this:

var lc:LayeredContainer = new LayeredContainer();
lc.createLayers("tiles", "whatever", "mask");

addChild(lc);

lc.layer("tiles").addChild(_some_tile_you_made_);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文