I would like to make a game where the background is wider than the screen and scrolls from right to left. How would I do that? Is the background just another sprite?
Gene
Offline
I don't think you can make a background bigger then the screen.
What I just thought of is to do this:
1. Create 2 or 3 (or more depending how wide you want it) images as seperate sprites. You can just leave background white.
2. For the scrolling affect, just chance the X position of the sprites by a positive number to make the illusion of scrolling right. And by a negative number to make the illusion of going left.
3. Make sure all the images have a bit of them on the screen.
Refer to my sample: http://scratch.mit.edu/projects/Greatness/4213
Enjoy
Offline
Greatness
I think your idea will work. I guess if I butt a second sprite up against it, one sprite can move off the screen while another moves onto the screen, giving the illusion of a continuous background (like in a Mario game).
Thank you.
Hammination
Offline
Pls check out my scrolling background - http://scratch.mit.edu/projects/uncleclives/4891
Offline
Hi,
How do you segment your backgrounds? What is the best program to use?
Any help - greatly appriciated,
G_O
Offline
Hi,
I used the free paint.net software (link - http://www.download.com/Paint-NET/3000-2192-10338146.html?part=dl-PaintNET&subj=dl&tag=button)
After opening your background click on layers followed by the rotate and zoom option. Once this window is open tick the option for tiling. To scroll the image in the direction you want use the pan option + or - x or y. I moved my backgrounds by a factor of 100 to the left each frame and then saved each screen (e.g back1, back 2 etc)
It's not the best way to scroll a backgrond and is tedious but does the job in scratch!
Offline
I made something that works better than I expected it to: http://scratch.mit.edu/projects/jmgibson/7644
It uses sprites to tile in subsections of a wrapped background image. When a tile is off frame it hides in order to reduce draw time. And a tile always displays itself on the appropriate side of the screen so it can wrap.
Here is a website that describes fixing wrap seams in Photoshop:
http://www.myjanee.com/tuts/tilings/tilings.htm
Here is a PS7 and CS series script for breaking up an images into component tiles. Ignore all the references to Google Maps. I started from Will's script to work specifically on them:
/******************************************************************************************/
/* Tile Carver for Photoshop 7
and Probably CS
Created by Will James
http://onNYTurf.com
Transparency option added by
Curtis Wyatt
http://gocalipso.com/
*/
//**** YOU SHOULD CUSTOMIZE THE FOLLOWING VARIABLE DEPENDING ON YOUR NEED ****
var ZoomLevel = 1; //<-- Enter the zoom level we want to create tiles for
var FolderPath = "C:\Documents and Settings\Johnny\Desktop\SCRATCHstuff\ic1396-2"; //<-- path to where we will save our tiles
// We start with the coordinates, zoom, and width of an upper left corner tile and generate everything from there
// We can calculate new tile values from these values for any zoom level without having to look up these details for each.
var OrgX = 0; //<-- the X value
var OrgY = 0; //<-- the Y value
var OrgZoomLevel = 1; //<-- the zoom level
var OrgTileWidth = 4; //<-- the number of tiles wide your full map area is
var OrgTileHeight = 4; //<-- the number of tiles high your full map area is
var PixelWidth = 256; //<-- Set by Google
var PixelHeight = 256; //<-- Set by Google and same as width, but we included to make it easier to understand how this script works
var Transparency = false; //<-- true if slicing file with transparencies, and you want to retain them, false if not as this is slower
//**** EVERYTHING BEYOND HERE SHOULD NOT BE TOUCHED UNLESS YOU KNOW WHAT YOU ARE DOING!!!
// Exponent Function
// we will need these later
function PowMe(a, b){
var o = a;
for (n = 1; n < b; n++){ o *= a; }
if (b==0){ o = 1; }
return o;
};
// via http://www.ps-scripts.com/bb/viewtopic.php?p=343
function takeSnapshot () {
var id686 = charIDToTypeID( "Mk " );
var desc153 = new ActionDescriptor();
var id687 = charIDToTypeID( "null" );
var ref119 = new ActionReference();
var id688 = charIDToTypeID( "SnpS" );
ref119.putClass( id688 );
desc153.putReference( id687, ref119 );
var id689 = charIDToTypeID( "From" );
var ref120 = new ActionReference();
var id690 = charIDToTypeID( "HstS" );
var id691 = charIDToTypeID( "CrnH" );
ref120.putProperty( id690, id691 );
desc153.putReference( id689, ref120 );
executeAction( id686, desc153, DialogModes.NO );
}
function revertToLastSnapshot() {
var docRef = app.activeDocument;
var hsObj = docRef.historyStates;
var hsLength = hsObj.length;
for (var i = hsLength-1; i > -1; i--) {
if(hsObj[i].snapshot) {
docRef.activeHistoryState = hsObj.getByName('Snapshot ' + i);
break;
}
}
}
var StartX = OrgX*PowMe(2,(OrgZoomLevel - ZoomLevel)); //******this will work as long as your ORG values are your furthest zoom*******
var StartY = OrgY*PowMe(2,(OrgZoomLevel - ZoomLevel)); //******this will work as long as your ORG values are your furthest zoom*******
var xTiles = OrgTileWidth*PowMe(2,(OrgZoomLevel - ZoomLevel)); //<-- calculate the number of tiles across
var yTiles = OrgTileHeight*PowMe(2,(OrgZoomLevel - ZoomLevel)); //<-- calculate the number of tiles down
var TotalTiles = xTiles * yTiles; //<-- calculate the total number of tiles
// Before we start cutting up images we make sure Photoshop is measuring things in terms of Pixels
preferences.rulerUnits = Units.PIXELS;
// Counters to track which x value and which y value we are on in our image tile grid
var xm = 0;
var ym = 0;
var TileX = StartX; //<-- Set out first Google X value - later used in file name
var TileY = StartY; //<-- Set out first Google Y value - later used in file name
// Cut 'em up
// For each tile we need to make, we repeat each step in this loop
for (n=1; n<TotalTiles+1; n++) {
// We cut up tiles column by column
// I.E. we cut up all the tiles for a given x value before moving on to the next x value.
// We do this by checking if the y value we are on is the last tile in a column
// We compare our y counter to our total y number of Tiles, if they are the same is we do the following
if (ym == yTiles){
xm += 1; //<-- Up the x value by 1, i.e. we move over to the next column
ym = 0; //<-- Reset the y value to 0 so we start back at the top of our new column
TileX += 1; //<-- Increase our Google X value for our file name
TileY = StartY; //We reset our Google Y value for out file name everytime we change columns
};
// Based on our our TileWidth and TileHeight and the column we are on we determine our selection origin and area values
MyXO = xm*(PixelWidth);
MyXL = xm*(PixelWidth)+(PixelWidth);
MyYO = ym*(PixelHeight);
MyYL = ym*(PixelHeight)+(PixelHeight);
// We make sure our source image is the active document
var srcDoc = activeDocument;
//Select Area and Copy
srcDoc.selection.select(Array (Array(MyXO, MyYO), Array(MyXL, MyYO), Array(MyXL, MyYL), Array(MyXO, MyYL)), SelectionType.REPLACE, 0, false);
if (Transparency) {
takeSnapshot();
srcDoc.crop(Array(MyXO, MyYO, MyXL, MyYL));
//Save New Doc
var saveMe = activeDocument;
//Set path to file and file name
saveFile = new File("ztile" +TileX+ "_" + TileY+ ".gif");
//Set save options
gifSaveOptions = new GIFSaveOptions();
gifSaveOptions.colors = 64;
gifSaveOptions.dither = Dither.NONE;
gifSaveOptions.matte = MatteType.NONE;
gifSaveOptions.preserveExactColors = 0;
gifSaveOptions.transparency = 1;
gifSaveOptions.interlaced = 0;
//Save the file and close it
saveMe.saveAs(saveFile, gifSaveOptions, true, Extension.LOWERCASE);
revertToLastSnapshot();
//saveMe.close(SaveOptions.DONOTSAVECHANGES);
}
else {
srcDoc.selection.copy();
//Paste to new Doc
var pasteDoc = documents.add(PixelWidth, PixelHeight, srcDoc.resolution, "Paste Target");
pasteDoc.paste();
pasteDoc = null;
//Save New Doc
var saveMe = activeDocument;
//Flatten
saveMe.flatten();
//Set path to file and file name
saveFile = new File("ztile" +TileX+ "_" + TileY+ ".gif");
//Set save options
gifSaveOptions = new GIFSaveOptions();
gifSaveOptions.colors = 64;
gifSaveOptions.dither = Dither.NONE;
gifSaveOptions.matte = MatteType.NONE;
gifSaveOptions.preserveExactColors = 0;
gifSaveOptions.transparency = 0;
gifSaveOptions.interlaced = 0;
//Save the file and close it
saveMe.saveAs(saveFile, gifSaveOptions, true,Extension.LOWERCASE);
saveMe.close(SaveOptions.DONOTSAVECHANGES);
}
//Advance Y counter for next image
ym += 1;
//Advance Google Y value for next image name
TileY += 1;
}
/**************************************************************/
Last edited by jmgibson (2007-06-03 05:02:38)
Offline
I have my own, here, with only 2 sprites for the background - identical cloud scenes.
http://scratch.mit.edu/projects/Mayhem/9702
I had real trouble getting them to join seamlessly - if I aimed to have my two sprites exactly their own width apart, there always seemed to be a gap. Its kinda fixed but I'd be interested in hearing if anyone else encountered the same problem.
A way to avoid this would have been to have my stage as a neutral colur (the sky) and to have the scrolling sprites be individual fluffy clouds. - or groups of fluffy clods on a transparent background.
Last edited by Mayhem (2007-06-03 08:09:05)
Offline