Thread: AnimatedSprite (GIF Sprite) - With transparent gif support!

Results 1 to 6 of 6
  1. #1 AnimatedSprite (GIF Sprite) - With transparent gif support! 
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    Hey there,

    I've recently tried adding .GIF support to client, and I've came across this thread, however, it did not support transparent gif (which I believe is what most people want, i.e to put over an interface)
    Anyways I've seen one of the comments there hinting on how it should be done, and while this might not be the most efficient way of doing so (I dunno how else it could be done)
    I got to fix it and decided to release it as it is really useful!

    Note: I haven't changed anything, except adding the support for transparency.

    Follow the guide on this thread and replace #update() with mine:

    Code:
        public void update() {
            clearPixels();
            try {
                Graphics g = buffer.getGraphics();
                if (g != null)
                    try {
                        if (!scaled) {
                            g.drawImage(image, 0, 0, component);
                        } else {
                            if (g instanceof Graphics2D) {
                                ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_RENDERING, getScaleDetail(scaleDetail));
                            }
                            g.drawImage(image, 0, 0, width, height, component);
                        }
                    } finally {
                        g.dispose();
                    }
    
            } catch (Exception x) {
            }
            overwritePixels();
        }
    
        //redraws the pixels
        public void clearPixels() {
            for (int i = 0; i < pixels.length; i++)
                pixels[i] = 0;
        }
    
        //overwrites the pixels to the rasterizer
        public void overwritePixels() {
            drawOffsetX = drawOffsetY = 0;
            resizeWidth = width;
            resizeHeight = height;
            raster = pixels;
        }

    Explanation:

    Quote Originally Posted by Joshua View Post
    Each frame of the gif is being copied to the rasterizer and overwriting the current pixels at the spots it is drawing. If you want to add support for transparent gifs, you'd have to redraw the image behind your gif before each frame of the gif is drawn. Or store specific pixels in a temporary array and just copy them back to the rasterizer between passes.
    I might have done it a bit different, but it seems to work with no FPS drop / any performance struggles.

    (I know its flicking at one point, I'm not sure if thats the gif or because we don't till all pixels are cleared so it could process some pixels cleared and some not, not sure)

    Attached image

    Credits;
    Joshua
    Killer 99
    Me
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Extreme Donator


    Join Date
    Dec 2016
    Posts
    383
    Thanks given
    99
    Thanks received
    66
    Rep Power
    340
    thanks
    Reply With Quote  
     

  4. #3  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    Quote Originally Posted by Kyansh View Post
    thanks
    No problem. Added media
    Reply With Quote  
     

  5. #4  
    ᗪ乇尺乇乙乙乇ᗪ

    lumplum's Avatar
    Join Date
    Nov 2015
    Posts
    1,145
    Thanks given
    529
    Thanks received
    1,463
    Rep Power
    5000
    Lmao this looks so cool
    Reply With Quote  
     

  6. #5  
    Super Donator

    StanDev's Avatar
    Join Date
    Apr 2014
    Posts
    660
    Thanks given
    82
    Thanks received
    255
    Rep Power
    592
    goodjob boi
    Reply With Quote  
     

  7. #6  
    Banned
    Join Date
    Sep 2017
    Posts
    123
    Thanks given
    1
    Thanks received
    7
    Rep Power
    0
    Looks rather decent.
    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

Similar Threads

  1. Sprites with transparent background
    By Exidia in forum Help
    Replies: 3
    Last Post: 08-20-2013, 02:52 AM
  2. Replies: 2
    Last Post: 02-07-2013, 04:37 PM
  3. Unanimated GIF's with better quality
    By La Lampara in forum Help
    Replies: 0
    Last Post: 08-01-2010, 04:51 PM
  4. How To make A Gif Text With photoshop.
    By PrataKosong in forum Tutorials
    Replies: 11
    Last Post: 12-14-2009, 03:43 PM
  5. Replies: 45
    Last Post: 09-23-2007, 01:37 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •