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
[Edited by Ed Mack on 07-22-2002 at 06:15 AM]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;
}
}
}
