dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [HOW TO] Resizing tile ?

  1. #1
    Senior Member
    Join Date
    Feb 2005
    Posts
    172

    [HOW TO] Resizing tile ?

    What is the easiest way to make a resizing tiled texture background with AS3 ? Tried it with draw functions, but it seems that I'm unable.

    Basicly, I want to create a tild background, which I can give layer blending properties.

  2. #2
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    you can use drawing methods, or load an image, to serve as the bitmap, then use beginBitmapFill. here's a basic e.g. that'll cover the stage with a checker pattern:[
    PHP Code:
    // create the bitmap, 4 x 4 with a white background
    var bitmap:BitmapData = new BitmapData(4,4,false,0xFFFFFF);
    // create a 2 x 2 black square on the top left corner
    bitmap.fillRect(new Rectangle(0,0,2,2),0);
    // create a 2 x 2 black square on the bottom right corner
    bitmap.fillRect(new Rectangle(2,2,2,2),0);

    // draw it with beginBitmapFill
    var back:Shape = new Shape();
    back.graphics.beginBitmapFill(bitmap);
    back.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
    this.addChild(back); 

  3. #3
    Senior Member
    Join Date
    Feb 2005
    Posts
    172
    how can I do with a jpeg file ?

  4. #4
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    Load a .jpg via a Loader object, then create the bitmap object demonstrated above but instead use the bitmapdata of the loaders content using .draw() or copyPixels().

  5. #5
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    an example as per jaquan's directions:
    PHP Code:
    var loader:Loader = new Loader(); 
    loader.contentLoaderInfo.addEventListener("complete",function(event:Event):void
        var 
    bitmap:BitmapData Bitmap(loader.content).bitmapData
        var 
    tile:Shape = new Shape(); 
        
    tile.graphics.beginBitmapFill(bitmap); 
        
    tile.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight); 
        
    addChild(tile); 
    } ); 
    loader.load(new URLRequest("http://www.yoursite.com/path/to/yourimage.jpg")); 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center