Thread: New sprite format (With opacity)

Results 1 to 8 of 8
  1. #1 New sprite format (With opacity) 
    Registered Member
    Yarnova's Avatar
    Join Date
    Jul 2007
    Age
    26
    Posts
    878
    Thanks given
    1
    Thanks received
    34
    Rep Power
    364
    Create a new file named Sprite.java and paste this into it:
    Code:
    import java.awt.*;
    import java.awt.image.PixelGrabber;
    import sign.signlink;
    
    public class Sprite extends Class30_Sub2_Sub1
    {
    
        public static String spriteDirectory = "./Sprites/";
        public int width;
        public int height;
        public int colors[];
        public int transparency[];
    
        public Sprite(String s, int i)
        {
            try
            {
                Image image = Toolkit.getDefaultToolkit().getImage(spriteDirectory + s + " " + i + ".png");
                MediaTracker mediatracker = new MediaTracker(client.component);
                mediatracker.addImage(image, 0);
                mediatracker.waitForAll();
                width = image.getWidth(client.component) / 2;
                height = image.getHeight(client.component);
                colors = new int[width * height];
                transparency = new int[width * height];
                PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, width, height, colors, 0, width);
                pixelgrabber.grabPixels();
                PixelGrabber pixelgrabber2 = new PixelGrabber(image, width, 0, width * 2, height, transparency, 0, width);
                pixelgrabber2.grabPixels();
                for(int i2 = 0; i2 < transparency.length; i2++)
                {
                    transparency[i2] = 0xffffff + (transparency[i2] + 1);
                    if(transparency[i2] == 0xff)
                    {
                        transparency[i2] = -1;
                    } else
                    {
                        transparency[i2] = (int)((((transparency[i2] >> 16) & 0xff) + ((transparency[i2] >> 8) & 0xff) + (transparency[i2] & 0xff)) / 3);
                    }
                }
            }
            catch(Exception e)
            {
                System.out.println("Invalid Sprite: " + s + " " + i);
                try
                {
                    Image image = Toolkit.getDefaultToolkit().getImage(spriteDirectory + "X.png");
                    MediaTracker mediatracker = new MediaTracker(client.component);
                    mediatracker.addImage(image, 0);
                    mediatracker.waitForAll();
                    width = 30;
                    height = 30;
                    colors = new int[width * height];
                    transparency = new int[width * height];
                    PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, width, height, colors, 0, width);
                    pixelgrabber.grabPixels();
                }
                catch(Exception e2)
                {
                    e2.printStackTrace();
                }
            }
        }
    
        public void draw(int x, int y)
        {
            int l = x + y * Class30_Sub2_Sub1.anInt1379;
            int i1 = 0;
            int j1 = height;
            int k1 = width;
            int l1 = Class30_Sub2_Sub1.anInt1379 - k1;
            int i2 = 0;
            if(y < Class30_Sub2_Sub1.anInt1381)
            {
                int j2 = Class30_Sub2_Sub1.anInt1381 - y;
                j1 -= j2;
                y = Class30_Sub2_Sub1.anInt1381;
                i1 += j2 * k1;
                l += j2 * Class30_Sub2_Sub1.anInt1379;
            }
            if(y + j1 > Class30_Sub2_Sub1.anInt1382)
            {
                j1 -= (y + j1) - Class30_Sub2_Sub1.anInt1382;
            }
            if(x < Class30_Sub2_Sub1.anInt1383)
            {
                int k2 = Class30_Sub2_Sub1.anInt1383 - x;
                k1 -= k2;
                x = Class30_Sub2_Sub1.anInt1383;
                i1 += k2;
                l += k2;
                i2 += k2;
                l1 += k2;
            }
            if(x + k1 > Class30_Sub2_Sub1.anInt1384)
            {
                int l2 = (x + k1) - Class30_Sub2_Sub1.anInt1384;
                k1 -= l2;
                i2 += l2;
                l1 += l2;
            }
            if(k1 <= 0 || j1 <= 0)
            {
                return;
            } else
            {
                draw2(i1, l, k1, j1, l1, i2);
                return;
            }
        }
    
        public void draw2(int j, int k, int l, int i1, int j1, int k1)
        {
            int color = 0;
            boolean invert = false;
            int opacity = 0;
            int l1 = -(l >> 2);
            l = -(l & 3);
            for(int i2 = -i1; i2 < 0; i2++)
            {
                for(int j2 = l1; j2 < 0; j2++)
                {
                    color = colors[j];
                    invert = transparency[j] == -1;
                    opacity = (int)(100 - (transparency[j++] / 2.55));
                    if(invert)
                    {
                        Class30_Sub2_Sub1.anIntArray1378[k] = 1 - Class30_Sub2_Sub1.anIntArray1378[k++];
                    } else
                    {
                        Class30_Sub2_Sub1.anIntArray1378[k] = mixColor(color, Class30_Sub2_Sub1.anIntArray1378[k++], opacity);
                    }
                    color = colors[j];
                    invert = transparency[j] == -1;
                    opacity = (int)(100 - (transparency[j++] / 2.55));
                    if(invert)
                    {
                        Class30_Sub2_Sub1.anIntArray1378[k] = 1 - Class30_Sub2_Sub1.anIntArray1378[k++];
                    } else
                    {
                        Class30_Sub2_Sub1.anIntArray1378[k] = mixColor(color, Class30_Sub2_Sub1.anIntArray1378[k++], opacity);
                    }
                    color = colors[j];
                    invert = transparency[j] == -1;
                    opacity = (int)(100 - (transparency[j++] / 2.55));
                    if(invert)
                    {
                        Class30_Sub2_Sub1.anIntArray1378[k] = 1 - Class30_Sub2_Sub1.anIntArray1378[k++];
                    } else
                    {
                        Class30_Sub2_Sub1.anIntArray1378[k] = mixColor(color, Class30_Sub2_Sub1.anIntArray1378[k++], opacity);
                    }
                    color = colors[j];
                    invert = transparency[j] == -1;
                    opacity = (int)(100 - (transparency[j++] / 2.55));
                    if(invert)
                    {
                        Class30_Sub2_Sub1.anIntArray1378[k] = 1 - Class30_Sub2_Sub1.anIntArray1378[k++];
                    } else
                    {
                        Class30_Sub2_Sub1.anIntArray1378[k] = mixColor(color, Class30_Sub2_Sub1.anIntArray1378[k++], opacity);
                    }
                }
    
                for(int k2 = l; k2 < 0; k2++)
                {
                    color = colors[j];
                    invert = transparency[j] == -1;
                    opacity = (int)(100 - (transparency[j++] / 2.55));
                    if(invert)
                    {
                        Class30_Sub2_Sub1.anIntArray1378[k] = 1 - Class30_Sub2_Sub1.anIntArray1378[k++];
                    } else
                    {
                        Class30_Sub2_Sub1.anIntArray1378[k] = mixColor(color, Class30_Sub2_Sub1.anIntArray1378[k++], opacity);
                    }
                }
    
                k += j1;
                j += k1;
            }
    
        }
    
        public static int mixColor(int sourceColor, int destinationColor, int opacity)
        {
            return (((int)((((sourceColor >> 16) & 0xff) * (opacity / (double)100)) + (((destinationColor >> 16) & 0xff) * (1 - (opacity / (double)100))))) << 16) + (((int)((((sourceColor >> 8) & 0xff) * (opacity / (double)100)) + (((destinationColor >> 8) & 0xff) * (1 - (opacity / (double)100))))) << 8) + ((int)(((sourceColor & 0xff) * (opacity / (double)100)) + ((destinationColor & 0xff) * (1 - (opacity / (double)100)))));
        }
    
    }
    And set spriteDirectory to where your sprite images are located.

    Now to use it go into client.java and find the sprite you want to change to the new format, for example
    Code:
                aClass30_Sub2_Sub1_Sub1_1001 = new Class30_Sub2_Sub1_Sub1(class44_2, "mapedge", 0);
    and replace it with this:
    Code:
                aClass30_Sub2_Sub1_Sub1_1001 = new Sprite("mapedge", 0);
    then replace all the
    Code:
    aClass30_Sub2_Sub1_Sub1_1001.method348(x, junk, y);
    with
    Code:
    aClass30_Sub2_Sub1_Sub1_1001.drawSprite(x, y);
    and change
    Code:
    Class30_Sub2_Sub1_Sub1 aClass30_Sub2_Sub1_Sub1_1001
    to
    Code:
    Sprite aClass30_Sub2_Sub1_Sub1_1001
    The sprite must have the colors on the left side of the image, and the transparency on the right side of it as shown in the sprite below.


    You can also use blue (0, 0, 255 or 0000ff) in the opacity for the color to be the inverted color of what is behind the sprite.
    Reply With Quote  
     

  2. #2  
    Why Am I Not Vet?!

    Clouds Mine's Avatar
    Join Date
    May 2008
    Age
    28
    Posts
    2,400
    Thanks given
    1
    Thanks received
    21
    Rep Power
    1478
    Sweet thanks for this
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Jun 2007
    Posts
    276
    Thanks given
    0
    Thanks received
    2
    Rep Power
    14
    Would this work the same if i replaced the sprite class in a refactored client?

    EDIT: i looked at the code, and nope, it dosent look like it.
    Reply With Quote  
     

  4. #4  
    Registered Member
    Jammy780's Avatar
    Join Date
    May 2008
    Posts
    1,320
    Thanks given
    13
    Thanks received
    47
    Rep Power
    619
    aClass30_Sub2_Sub1_Sub1_1001.drawSprite(x, y);

    Drawsprite is for a Renamed client.
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Jun 2007
    Posts
    276
    Thanks given
    0
    Thanks received
    2
    Rep Power
    14
    Quote Originally Posted by imjammy780 View Post
    aClass30_Sub2_Sub1_Sub1_1001.drawSprite(x, y);

    Drawsprite is for a Renamed client.
    Yes but what is class30_sub2_sub1_sub1? The sprite class in refactored clients.
    Reply With Quote  
     

  6. #6  
    Banned HEADLEY's Avatar
    Join Date
    Dec 2007
    Age
    25
    Posts
    366
    Thanks given
    5
    Thanks received
    1
    Rep Power
    0
    Omg Thank You!
    Reply With Quote  
     

  7. #7  
    Registered Member
    Yarnova's Avatar
    Join Date
    Jul 2007
    Age
    26
    Posts
    878
    Thanks given
    1
    Thanks received
    34
    Rep Power
    364
    Quote Originally Posted by imjammy780 View Post
    aClass30_Sub2_Sub1_Sub1_1001.drawSprite(x, y);

    Drawsprite is for a Renamed client.
    drawSprite is a method in the Sprite.java i made, this is for non-refactored clients and if you did it right it will work.
    Reply With Quote  
     

  8. #8  
    Joshz
    Guest
    Thank you so much dude, you rock.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •