flixel-ui icon indicating copy to clipboard operation
flixel-ui copied to clipboard

Repeating sprite patterns for menu bars and backgrounds

Open xerosugar opened this issue 8 years ago • 7 comments

I'm adding this because I need it myself :) Maybe this could be build from a modified flxbackdrop or something - with customizable height/width.

xerosugar avatar Jan 13 '16 14:01 xerosugar

I believe you can do this already with FlxUI9SliceSprite, by using tiling instead of scaling?

But perhaps you mean something different, care to elaborate?

larsiusprime avatar Jan 13 '16 17:01 larsiusprime

ah, I didn't know there was a tiling option for that :) but I'll just show a picture of what I want to do: http://postimg.org/image/q33i0wpft/

In other words, use an image and then repeat it vertically/horizontally or both.

xerosugar avatar Jan 13 '16 17:01 xerosugar

Yeah you can use FlxUI9SliceSprite with tiling for this, but it's probably not the most efficient solution.

Any reason you don't want to use a FlxTileMap?

larsiusprime avatar Jan 13 '16 18:01 larsiusprime

I didn't even consider a tilemap, but that sounds like overkill to me. right now I'm just doing this:

    var bg:FlxSprite;
    function makeBackground():Void
    {
        var lastX:Int = 0;
        var lastY:Int = 0;
        var imgAssetStr = "assets/images/dirt_bg.png";
        var dirtPattern:FlxSprite = new FlxSprite(0, 0, imgAssetStr);

        bg = new FlxSprite(0, 0);
        bg.makeGraphic(FlxG.width, FlxG.height, FlxColor.TRANSPARENT);

        while (lastY < FlxG.height)
        {
            while (lastX < FlxG.width)
            {
                bg.stamp(dirtPattern, Std.int(lastX), Std.int(lastY));
                lastX += Std.int(dirtPattern.width);
            }

            lastX = 0;
            lastY += Std.int(dirtPattern.height);
        }

        dirtPattern.destroy();
        add(bg);
    }();

and it works. but I'm not sure how I'll handle potential optional screen sizes etc. for menu bars and text elements. that's why I was thinking of using FlixelUI instead.

xerosugar avatar Jan 13 '16 18:01 xerosugar

Ah I see. I'll see if I can think of something that's performant, convenient, and easily resizable, and see where it naturally fits in the existing API.

Do you have a specific invocation in mind you'd like to use?

larsiusprime avatar Jan 13 '16 18:01 larsiusprime

Not really no... but if I were to make one up right now, how about (without knowing how FlxUI works...):

widget.repeat(startPosX, startPosY, FlxUI.Vertical&FlxUI.Horizontal, spacingX, spacingY, ?targetArea:FlxRectangle); // if areaRec is provided, posx/y is ignored

(maybe css background logic can serve as inspiration as well: https://developer.mozilla.org/en/docs/Web/CSS/background-repeat)

xerosugar avatar Jan 13 '16 19:01 xerosugar

There is a FlxTiledSprite addon which could be used for this: https://api.haxeflixel.com/flixel/addons/display/FlxTiledSprite.html

xaedes avatar Dec 17 '18 14:12 xaedes