Originally Posted by
Seven
Thanks man appreciate it.
You're welcome
Thanks, you're welcome.
Cache sprite doesn't have anything to do with drawing the outline of sprites, iirc.
This method in Sprite class does that.
Code:
private void method349(int ai[], int ai1[], int j, int k, int l, int i1, int j1, int k1) {
int i;// was parameter
int l1 = -(l >> 2);
l = -(l & 3);
for (int i2 = -i1; i2 < 0; i2++) {
for (int j2 = l1; j2 < 0; j2++) {
i = ai1[j++];
if (i != 0 && i != -1) {
ai[k++] = i;
} else {
k++;
}
i = ai1[j++];
if (i != 0 && i != -1) {
ai[k++] = i;
} else {
k++;
}
i = ai1[j++];
if (i != 0 && i != -1) {
ai[k++] = i;
} else {
k++;
}
i = ai1[j++];
if (i != 0 && i != -1) {
ai[k++] = i;
} else {
k++;
}
}
for (int k2 = l; k2 < 0; k2++) {
i = ai1[j++];
if (i != 0 && i != -1) {
ai[k++] = i;
} else {
k++;
}
}
k += j1;
j += k1;
}
}
Refactored version
Code:
private void draw(int raster[], int[] image, int colour, int sourceIndex, int destIndex, int width, int height, int destStep,
int sourceStep) {
int minX = -(width >> 2);
width = -(width & 3);
for (int y = -height; y < 0; y++) {
for (int x = minX; x < 0; x++) {
colour = image[sourceIndex++];
if (colour != 0) {
raster[destIndex++] = colour;
} else {
destIndex++;
}
colour = image[sourceIndex++];
if (colour != 0) {
raster[destIndex++] = colour;
} else {
destIndex++;
}
colour = image[sourceIndex++];
if (colour != 0) {
raster[destIndex++] = colour;
} else {
destIndex++;
}
colour = image[sourceIndex++];
if (colour != 0) {
raster[destIndex++] = colour;
} else {
destIndex++;
}
}
for (int k2 = width; k2 < 0; k2++) {
colour = image[sourceIndex++];
if (colour != 0) {
raster[destIndex++] = colour;
} else {
destIndex++;
}
}
destIndex += destStep;
sourceIndex += sourceStep;
}
}
Just make sure when you're loading your cache sprites that method above is being called correctly.
the method is being called correctly... but once I pack the sprites instead of loading them externally it starts working..
I think its the way the myPixels array is handled when loading from cache:
Code:
public Sprite(StreamLoader streamLoader, String s, int i) {
Stream stream = new Stream(streamLoader.getDataForName(s + ".dat"));
Stream stream_1 = new Stream(streamLoader.getDataForName("index.dat"));
stream_1.currentOffset = stream.readUnsignedWord();
this.anInt1444 = stream_1.readUnsignedWord();
this.anInt1445 = stream_1.readUnsignedWord();
int j = stream_1.readUnsignedByte();
int[] ai = new int[j];
int i1;
for(i1 = 0; i1 < j - 1; ++i1) {
ai[i1 + 1] = stream_1.read3Bytes();
if(ai[i1 + 1] == 0) {
ai[i1 + 1] = 1;
}
}
for(i1 = 0; i1 < i; ++i1) {
stream_1.currentOffset += 2;
stream.currentOffset += stream_1.readUnsignedWord() * stream_1.readUnsignedWord();
++stream_1.currentOffset;
}
this.anInt1442 = stream_1.readUnsignedByte();
this.anInt1443 = stream_1.readUnsignedByte();
this.myWidth = stream_1.readUnsignedWord();
this.myHeight = stream_1.readUnsignedWord();
i1 = stream_1.readUnsignedByte();
int j1 = this.myWidth * this.myHeight;
this.myPixels = new int[j1];
int l1;
if(i1 == 0) {
for(l1 = 0; l1 < j1; ++l1) {
this.myPixels[l1] = ai[stream.readUnsignedByte()];
}
} else {
if(i1 == 1) {
for(l1 = 0; l1 < this.myWidth; ++l1) {
for(int i2 = 0; i2 < this.myHeight; ++i2) {
this.myPixels[l1 + i2 * this.myWidth] = ai[stream.readUnsignedByte()];
}
}
}
}
}
and this is the external loading method:
Code:
public Sprite(byte spriteData[]) {
try {
Image image = Toolkit.getDefaultToolkit().createImage(spriteData);
ImageIcon sprite = new ImageIcon(image);
myWidth = sprite.getIconWidth();
myHeight = sprite.getIconHeight();
anInt1444 = myWidth;
anInt1445 = myHeight;
anInt1442 = 0;
anInt1443 = 0;
myPixels = new int[myWidth * myHeight];
PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, myWidth,
myHeight, myPixels, 0, myWidth);
pixelgrabber.grabPixels();
image = null;
setTransparency(255, 0, 255);
} catch (Exception _ex) {
System.out.println(_ex);
}
}