A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: [Problem] cutting an image into tiles

  1. #1
    Senior Member mandissected's Avatar
    Join Date
    Jan 2005
    Location
    Berwick - England
    Posts
    338

    [Problem] cutting an image into tiles

    I have a background in flash I want to cut up into tiles for scrolling. I can't seem to figure out how to do this, can someone please put me out of my misery?

  2. #2
    Untitled-1.fla strille's Avatar
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    1,626
    There are several programs that lets you split up an image into several.

    I've used a program called Splitz: http://134.53.40.1/dms/rajkumtm/splitz/

  3. #3
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    Note: I'm assuming this is a map which only goes left and right, and doesn't move vertically.

    Just select a screen-sized portion of the map, turn it into a movie clip (let's say tile0), then the next screen-sized portion of it will be tile1, the next will be tile2, and so on. So assume you start off at tile5. If you press left, it'll attach tile4 to the left of it. Keep on going left, and eventually you'll have to attach tile3, too (and remove tile5).
    http://www.birchlabs.co.uk/
    You know you want to.

  4. #4
    Untitled-2.fla
    Join Date
    Jul 2002
    Posts
    391
    if you're using MX04, you can use this


    Code:
    /**
     * Save As	: TileSet.jsfl
     * Save In	: C:\Documents and Settings\[username]\Local Settings\Application Data\Macromedia
     *		  \Flash MX 2004\en\Configuration\Commands
     *
     * Works	: Flash MX 2004
     * Usage	:
     *		  Create a new Flash document, create a blank movieclip named 'tileset', import yout tileset.gif|jpg into that
     *		  Align the tileset to the top-left and break the image apart (Ctrl + B | Modify -> Break Apart )
     *
     *		  Next select Commands -> TileSet; this will genarate a tileset
     *		  Tiles are named tileX where X is a incremented number
     *
     *		  By default the tiles are not set to be exported at the first frame, if you want them to 
     *		  alter the indicated line in the for loop
     */
    
    var tileW	= 32	// the width of your tile
    var tileH	= 32	// the height of your tile
    
    var setW	= 10	// the number of horizontal tiles in your tileset
    var setH	= 10	// the number of vertical tiles in your tileset
    
    var lib	= fl.getDocumentDOM ( ).library;
    
    var source	= 'tileset';
    
    var tileNum	= -1
    
    for ( var y = 0; y < setH; y++ )
    {
    	for ( var x = 0; x < setW; x++ )
    	{
    		var name	= 'tile' + ( ++tileNum )
    
    		lib.addNewItem		( 'movie clip', 'tiles/' + name );
    		lib.setItemProperty	( 'linkageExportForAS', true );
    		
    		// export at first frame?
    		lib.setItemProperty	( 'linkageExportInFirstFrame', false );
    
    		fl.getDocumentDOM ( ).library.selectItem ( source );
    		fl.getDocumentDOM ( ).library.editItem ( );
    		fl.getDocumentDOM ( ).setSelectionRect ( { left: x * tileW, top: y * tileH, right: ( x +1 ) * tileW, bottom: ( y + 1 ) * tileH } );
    		fl.getDocumentDOM ( ).clipCopy ( );
    		fl.getDocumentDOM ( ).library.selectItem ( 'tiles/' + name );
    		fl.getDocumentDOM ( ).library.editItem ( );
    		fl.getDocumentDOM ( ).clipPaste ( true );
    		fl.getDocumentDOM ( ).moveSelectionBy ( {x: -x * tileW, y: -y * tileH } );
    		fl.getDocumentDOM ( ).selectNone ( );
    	}
    }

  5. #5
    hmm Pugger's Avatar
    Join Date
    Sep 2003
    Location
    Perth, Australia
    Posts
    616
    Any idea if the script will work on a mac?

    I tried but it complained about the clipCopy function when ever I tried to run it.

  6. #6
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    Are you kidding? The Flash Player's practically famous for its cross-platform portability. Unless Macromedia have betrayed us (_again_), then it ought to work fine.



    I salute you, Comrade Macski!
    http://www.birchlabs.co.uk/
    You know you want to.

  7. #7
    Untitled-2.fla
    Join Date
    Jul 2002
    Posts
    391
    I had the same problem on a pc when i was writing the script, I can't remember what or how I solved it, maybe try running the code on this .fla (see if it makes any difference) just resize the image (in the fla) to 320x320

    tell me how you get on

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