A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Whats the matter with this (tilebased) issue ?

  1. #1
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    I was mucking around with the out of society scrolling and i tried to get it to scrool up and down but in my attempts i still cant work it out here the code the stuffed up bit is //commented with //up //down

    take a look

    Code:
    
    
    fscommand ( "allowscale", false );
    
    // includes the map array from an external file
    #include "map.as"
    
    // how big is our map?
    mapW = map1[0].length;
    mapH = map1.length;
    
    // the visible area, what we should draw.
    visAreaX = 10;
    visAreaY = 9;
    
    // the tiles width and height
    tileW = 16;
    tileH = 16;
    
    // the x and y positions where our map should be positioned on the stage
    startX = 140;
    startY = 40;
    
    // used later on for the actual scrolling
    majorX = 0;
    majorY = 0;
    scrSpeed = 3;
    
    // attach an empty movieclip from library, inside this we draw our map.
    this.attachMovie("empty", "scrClip", 0);
    this.scrClip._x = startX;
    this.scrClip._y = startY;
    
    // attach a cover, to make it look smooth
    this.attachMovie("cover", "cover", 1);
    this.cover._x = startX;
    this.cover._y = startY;
    
    // buildMap-function
    function buildMap () {
    	// i = Height loop || j = Width loop
    	for ( i=0; i<(visAreaY); ++i ) {
    		for ( j=0; j<(visAreaX+1); ++j ) {
    			this.scrClip.attachMovie("tile", "t_"+i+"_"+j, ++d);
    			this.scrClip["t_"+i+"_"+j]._x = j*tileW;
    			this.scrClip["t_"+i+"_"+j]._y = i*tileH;
    			this.scrClip["t_"+i+"_"+j].gotoAndStop ( map1[i ][j][0] );
    		}
    	}
    }
    
    buildMap();
    
    // scroll-function
    function doScroll (dir) {
    	// right
    	if ( dir == "right" && j <= mapW ) {
    		this.scrClip._x -= scrSpeed;
    		majorX += scrSpeed;
    		if ( majorX >= tileW ) {
    			for ( var lasti=(i-visAreaY); lasti<(i); ++lasti ) {
    				for ( var lastj=j; lastj<(j+1); ++lastj ) {
    					this.scrClip.attachMovie("tile", "t_"+lasti+"_"+lastj, ++d);
    					this.scrClip["t_"+lasti+"_"+lastj]._x = lastj*tileW;
    					this.scrClip["t_"+lasti+"_"+lastj]._y = lasti*tileH;
    					this.scrClip["t_"+lasti+"_"+lastj].gotoAndStop ( map1[lasti][lastj][0] );
    					removeMovieClip ( this.scrClip["t_"+lasti+"_"+(lastj-visAreaX-1)] );
    				}
    			}
    			++j;
    			majorX -= tileW;
    		}
    	}
    
    	// left
    	if ( dir == "left" && (j-visAreaX) > 0 ) {
    		this.scrClip._x += scrSpeed;
    		majorX -= scrSpeed;
    		if ( majorX <= 0 ) {
    			--j;
    			for ( var lasti=(i-visAreaY); lasti<(i); ++lasti ) {
    				for ( var lastj=(j-visAreaX-1); lastj<(j-visAreaX); ++lastj ) {
    					this.scrClip.attachMovie("tile", "t_"+lasti+"_"+lastj, ++d);
    					this.scrClip["t_"+lasti+"_"+lastj]._x = lastj*tileW;
    					this.scrClip["t_"+lasti+"_"+lastj]._y = lasti*tileH;
    					this.scrClip["t_"+lasti+"_"+lastj].gotoAndStop ( map1[lasti][lastj][0] );
    					removeMovieClip ( this.scrClip["t_"+lasti+"_"+(lastj+visAreaX+1)] );
    				}
    			}
    			majorX += tileW;
    		}
    	}
    	// right
    	if ( dir == "up" && i <= mapH ) {
    		this.scrClip._y -= scrSpeed;
    		majorY += scrSpeed;
    		if ( majorY >= tileH ) {
    			for ( var lastj=(j-visAreaX); lastj<(j); ++lastj ) {
    				for ( var lasti=i; lasti<(i+1); ++lasti ) {
    					this.scrClip.attachMovie("tile", "t_"+lastj+"_"+lasti, ++d);
    					this.scrClip["t_"+lastj+"_"+lasti]._x = lasti*tileH;
    					this.scrClip["t_"+lastj+"_"+lasti]._y = lastj*tileW;
    					this.scrClip["t_"+lastj+"_"+lasti].gotoAndStop ( map1[lastj][lasti][0] );
    					removeMovieClip ( this.scrClip["t_"+lastj+"_"+(lasti-visAreaY-1)] );
    				}
    			}
    			++i;
    			majorY -= tileH;
    		}
    	}
    
    	// down
    	if ( dir == "down" && (j-visAreaX) > 0 ) {
    		this.scrClip._x += scrSpeed;
    		majorX -= scrSpeed;
    		if ( majorX <= 0 ) {
    			--j;
    			for ( var lastj=(j-visAreaY); lastj<(j); ++lastj ) {
    				for ( var lasti=(i-visAreaY-1); lasti<(i-visAreaY); ++lasti ) {
    					this.scrClip.attachMovie("tile", "t_"+lastj+"_"+lasti, ++d);
    					this.scrClip["t_"+lastj+"_"+lasti]._x = lasti*tileH;
    					this.scrClip["t_"+lastj+"_"+lasti]._y = lastj*tileW;
    					this.scrClip["t_"+lastj+"_"+lasti].gotoAndStop ( map1[lastj][lasti][0] );
    					removeMovieClip ( this.scrClip["t_"+lastj+"_"+(lasti+visAreaY+1)] );
    				}
    			}
    			majorY += tileH;
    		}
    	}
    
    }
    
    [Edited by Ed Mack on 07-22-2002 at 06:15 AM]

  2. #2
    Senior Member Genesis F5's Avatar
    Join Date
    Jan 2002
    Location
    Unallocated memory
    Posts
    1,845
    In this part:


    Code:
    // how big is our map?
    mapW = map1[0].length;
    mapH = map1.length;

    was mapH supposed to be mapH = map1[J].length; ?


    just wondering, since I hadn't seen "J" defined in the initial code.


    -genesis f5



  3. #3
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    j is defined in the bulid map function

    Code:
    
    function buildMap () {
    	// i = Height loop || j = Width loop
    	for ( i=0; i<(visAreaY); ++i ) {
    		for ( j=0; j<(visAreaX+1); ++j ) {
    			this.scrClip.attachMovie("tile", "t_"+i+"_"+j, ++d);
    			this.scrClip["t_"+i+"_"+j]._x = j*tileW;
    			this.scrClip["t_"+i+"_"+j]._y = i*tileH;
    			this.scrClip["t_"+i+"_"+j].gotoAndStop ( map1[j][0] );
    		}

  4. #4
    Senior Member
    Join Date
    Apr 2002
    Posts
    167
    Originally posted by hooligan2001
    [Edited by Ed Mack on 07-22-2002 at 06:15 AM]
    Heh, I guess Ed Mack edited your post and changed what was wrong in the code then?

  5. #5
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    Dont think he did he just minimise my code due to the fact it was so big

    if anyone can fix my problem please be my guest

  6. #6
    Gross Pecululatarian Ed Mack's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    2,954
    I just put a small tag on it ... Check my site in a few days for scrolling help (If you're on my mailing list, then you'll be told about it)

  7. #7
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    k thanks heaps ed

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