Awesomeness
Joined: 01 Feb 2010
Posts: 5
|
Posted: Thu Sep 22, 2011 5:13 pm Post subject: How to make a tiled image? |
|
|
I am trying to make tiled images for a game. I'd like to be able to generate an image with a script that will be able to take a small image with different colors representing each (32px by 32px) tile to generate a "map" I can put into my game. This would save tons of copy/pasting.
So it could take a 10x10 px image with a bunch of pixels in colors, each representing a certain tile, and it would output a 320x320 px image with all the tiles in the right places.
How can I do this? Is it even possible? |
|
Paul R
Joined: 06 Apr 2010
Posts: 57
|
Posted: Fri Sep 23, 2011 1:45 pm Post subject: |
|
|
If you save your 10pixel x 10pixel as a Photoshop Raw, Interleaved no header
The following code should create the 320x320 map.
Code: |
File.prototype.readByte = function() {
return this.read(1).charCodeAt(0);
};
var rawFile = File.openDialog("Please select Raw Image");
rawFile.encoding = 'BINARY';
rawFile.open('r');
var FillColor = new SolidColor;
app.documents.add(new UnitValue(320,'px'),new UnitValue(320,'px'),72,"Colour Map");
var count = 0;
while(!rawFile.eof){
FillColor.rgb.red = rawFile.readByte();
FillColor.rgb.green = rawFile.readByte();
FillColor.rgb.blue = rawFile.readByte();
colourSquare(count,FillColor);
count++;
}
rawFile.close();
function colourSquare(count,Colour){
var constant = 32;
var line = parseInt(count/10);
var LEFT = 0 + (((count %10)) * constant);
var TOP = line * constant;
var RIGHT = constant + ((count %10) * constant);
var BOTTOM = (line * constant) + constant;
activeDocument.selection.select([[LEFT,TOP], [RIGHT,TOP], [RIGHT,BOTTOM], [LEFT, BOTTOM]], SelectionType.REPLACE, 0, false);
activeDocument.selection.fill(Colour, ColorBlendMode.NORMAL, 100);
activeDocument.selection.deselect();
}
|
|
|