开发者

AS3 - Background pattern movieclip

How can I use a movieclip instead of a bitmap for the tile background pattern?

var tile:BitmapData = new tileImg(0,0);
v开发者_如何学Goar tileLayer:Sprite;

function tileBgF(e:Event=null):void {   
    tileLayer = new Sprite();
    tileLayer.graphics.beginBitmapFill(tile);
    tileLayer.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
    tileLayer.graphics.endFill(); 
    addChildAt(tileLayer,0);
}

Thanks. Uli


function tileBgF(e:Event=null):void {   
    tileLayer = new Sprite();

    var bgClip:MovieClip = new MyClip();
    var i:int = 0;
    var j:int = 0;
    while(bgClip.x < stage.stageWidth) {
        bgClip = new MyClip();
        while (bgClip.y < stage.stageHeight) {
            bgClip = new MyClip();
            tileLayer.addChild(bgClip);
            bgClip.x = bgClip.width * i;
            bgClip.y = bgClip.height * j;

            j++;
        }

        j = 0;
        i++;
    }

    addChildAt(tileLayer,0);
}

This is assuming you have some custom movieclip that you want to use (MyClip in my example) and also assuming that you don't have other data on these movie clips and a new instance is sufficient for use as background elements.

Also worth noting, this is going on the assumption that either it doesn't matter if the movieclips are partially cropped by the stage edges or that they're sized perfectly to fit within the stage bounds in a nice even number.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜