I would like to make it so that when a character (picture or shape) moves it leaves a trail behind it that keeps getting more transparent. how would i start. If you jump the trail should follow up then down. Can anyone help me? Thanks

an idea:
say the shape is that of a star. you want more transparent stars to follow behind it. my idea is that you need to specify the number of stars first. say that are five stars, firs (1), second (2), 3, 4 5. when you initialize the app, each star has a position inside your screen. after this, every change that happens, should only be reflected on star one changing its position. star two assumes the previous position of star one, star three assumes the previous position of star two, star four that of star three, and star five that of star four. hope this helps, and if you write the app, share your code please. I would like to see how it turned out.

ok I will and is there a transparency changer in java. so the first star is solid (100) and 2 is 80 and 3 is 60 and 4 is 40 and 5 is 20. so it seems like the star is moving so fast that it leaves a trail. I would like to change the transparency of the stat without actually chancing the whole color.

Edited 5 Years Ago by sirlink99: n/a

This is what I have so far. it rust goes right, no up or down. not even a left. I'll keep working on it and I'll keep posting. I couldn't figure out how to use the brighter function. if anyone else has any solutions feel free to post. I just edited the code now the square bounces.

// The "Trail" class.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class Trail extends Applet implements KeyListener, Runnable
{
    // Place instance variables here
    int s1x = 0, s2x = -5, s3x = -10, s4x = -15, s5x = -20;
    int s1y = 30;
    private Image dbImage;
    private Graphics dbg;
    int dx = 0;
    Thread thread;
    Color sq1, sq2, sq3, sq4, sq5;

    public void init ()
    {
        resize (700,90);
    
        addKeyListener (this);


        // Place the body of the initialization method here
    } // init method


    public void start ()
    {
        thread = new Thread (this);
        thread.start ();
    }


    public void stop ()
    {
        thread.stop ();
    }


    public void run ()
    {

        Thread.currentThread ().setPriority (Thread.MIN_PRIORITY);
        while (true)
        {

            // Delay for 20 milliseconds
            try
            {
                Thread.sleep (20);
            }
            catch (InterruptedException e)
            {
            }

            starPlacement ();
            if (s1x == 670 || s1x == 0){
            dx = -dx;
            }
            repaint ();
            Thread.currentThread ().setPriority (Thread.MAX_PRIORITY);
        }


    }


    public void paint (Graphics g)
    {
        g.setColor (sq5);
        g.fillRect (s5x, s1y, 30, 30);
        g.setColor (sq4);
        g.fillRect (s4x, s1y, 30, 30);
        g.setColor (sq3);
        g.fillRect (s3x, s1y, 30, 30);
        g.setColor (sq2);
        g.fillRect (s2x, s1y, 30, 30);
        g.setColor (sq1);
        g.fillRect (s1x, s1y, 30, 30);
        // Place the body of the drawing method here
    } // paint method


    public void keyPressed (KeyEvent e)
    {
        int key = e.getKeyCode ();

        if (key == KeyEvent.VK_RIGHT)
        {
            dx = 5;
        }
    }


    public void keyReleased (KeyEvent e)
    {
    }


    public void keyTyped (KeyEvent e)
    {
    }


    public void starPlacement ()
    {
        s5x = s4x;
        s4x = s3x;
        s3x = s2x;
        s2x = s1x;
        s1x += dx;

        sq1 = new Color (0, 0, 0);
        sq2 = new Color (50, 50, 50);
        sq3 = new Color (100, 100, 100);
        sq4 = new Color (150, 150, 150);
        sq5 = new Color (200, 200, 200);

        repaint ();

    }


    public void update (Graphics g)
    {
        // initialize doublebuffers

        dbImage = createImage (this.getSize ().width, this.getSize ().height);
        dbg = dbImage.getGraphics ();


        // save background
        dbg.setColor (getBackground ());
        dbg.fillRect (0, 0, this.getSize ().width, this.getSize ().height);

        // draw foreground on background
        dbg.setColor (getForeground ());
        paint (dbg);

        // Now indicate ready drawn picture Offscreen on the right screen
        g.drawImage (dbImage, 0, 0, this);
    }
} // Trail class

Edited 5 Years Ago by sirlink99: new code

This article has been dead for over six months. Start a new discussion instead.