Page 3 of 3 FirstFirst 123
Results 41 to 58 of 58
  1. #41
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    i dont think the program would be useful if you can't use the same image as me, but how do you set the alpha property? Does it have something to do with the AffineTransform class?

  2. #42
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: game engine trouble

    Without a program that shows the problem, I can't work on a solution.
    use the same image as me
    Build one in the program or attach it to the forum's thread.
    If you don't understand my response, don't ignore it, ask a question.

  3. #43
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    how do you set the apha thing you mentioned

  4. #44
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: game engine trouble

    Look at the Color class.
    If you don't understand my response, don't ignore it, ask a question.

  5. #45
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    there are no set methods in the color class... so how do you modify the alpha value?

  6. #46
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: game engine trouble

    See the PixelGrabber class for ways to change colors.
    If you don't understand my response, don't ignore it, ask a question.

  7. #47
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    this class seems to be able to retrieve color and modify it on an image, but how can I use it to make parts of the image opaque?

  8. #48
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: game engine trouble

    The color's alpha value controls opaqueness.
    If you don't understand my response, don't ignore it, ask a question.

  9. #49
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    this snippet of code is supposed to make a single color transparent, but I dont understand anything but bits and pieces of it. Can you help me to do so? First off, is there a good tutorial somewhere for RGB image filters, b/c I havn't ever used them before. Next the return statement, I don't understand the logic of it or the purpose of the shift operator.

    Java Code:
    private Image TransformGrayToTransparency(BufferedImage image) 
    { 
    	ImageFilter filter = new RGBImageFilter() 
    	{ 
    		public final int filterRGB(int x, int y, int rgb) 
    		{ 
    			return (rgb << 8) & 0xFF000000; 
    		} 
    	}; 
    
    	ImageProducer ip = new FilteredImageSource(image.getSource(), filter); 
    	return Toolkit.getDefaultToolkit().createImage(ip); 
    }

  10. #50
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: game engine trouble

    Where there any comments by the author of the program explaining what it does? I've never used a filter.

    To see what the shift operator does, print out the int value before and after the shift to see what if does.

    Use the Integer class's toHexString() method to format the int value to see what happens to the bits in the int variable.
    If you don't understand my response, don't ignore it, ask a question.

  11. #51
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    I really just want an explination of that return statement at the moment.

    here is where I got that code:
    java - How to make a color transparent in a BufferedImage and save as PNG - Stack Overflow

  12. #52
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: game engine trouble

    explination of that return statement at the moment.
    Java Code:
    return Toolkit.getDefaultToolkit().createImage(ip);
    Read th API doc for the class and method it uses.
    If you don't understand my response, don't ignore it, ask a question.

  13. #53
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    not that return statement, the one on line 7. I don't understand why he has hexadecimal numbers there, or why the book that taught me what hexadecimal was said it was used often when working with color values...

  14. #54
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: game engine trouble

    As I said before add a println statement to print out the values that are created by the shift and & to see what they do. Write a 5 line program that does some shifts and ANDs and print out the before and after to see what happens.

    Hexadecimal numbers are easier to understand when used with the AND(&) and OR(|) operators. You can see that the AND is clearing all the bits except for the top (leftmost) 8 bits. You use AND to clear bits and OR to set bits.
    If you don't understand my response, don't ignore it, ask a question.

  15. #55
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    I am going to play around with hexadecimal numbers for a bit... In the meantime, I have wracked my brain, but cannot think of any way to do what I need. this program below draws a line from the point (250,250) to wherever you click, a black dot also flies across the screen. Pretend that the player is at the point (250,250). I want to make it so that wherever I click It will fire a black ball in that direction, but I cannot think of a way to do this that will work for every direction. Any thoughts?

    Java Code:
    //this can be used to rid yourself of flickering
    import java.awt.*;
    import java.awt.image.BufferStrategy;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.util.Timer;
    import java.util.TimerTask;
    import java.awt.Rectangle;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import java.awt.image.BufferedImage;
    import java.awt.geom.Ellipse2D.Double;
    import java.awt.geom.Ellipse2D;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseEvent;
    public class TRYBufferStrategy extends Fram implements MouseListener
    {
        Panel base = new Panel();
        Canvas canvas = new Canvas();
        Timer t = new Timer();
        int x=50,y=50, count=0,mx=250,my=250;
        BufferStrategy strategy;
        BufferedImage face;
        Ellipse2D shot = new Ellipse2D.Double(50,50,5,5);
        TRYBufferStrategy()
        {
            super("TRYBufferStrategy");
            setSize(800,600);
            //setIgnoreRepaint(true);
            add(base);
            //canvas.setPreferredSize(new Dimension(this.getWidth(),this.getHeight()));
            setIgnoreRepaint(true);
            base.setLayout(null);
            base.add(canvas);
            canvas.setBounds(0,0,getWidth(),getHeight());
            canvas.setIgnoreRepaint(true);
            canvas.addMouseListener(this);
            //setUndecorated(true);
            setVisible(true);
            
            try
            {
                face = ImageIO.read(getClass().getClassLoader().getResource("pic/hills.jpg"));
            }
            catch(IOException e) {}
            canvas.createBufferStrategy(2);
            strategy = canvas.getBufferStrategy();
            t.schedule(new TimerTask()
                        {
                            public void run()
                            {
                                ++count;
                                strategy = canvas.getBufferStrategy();
                                do
                                {
                                    do
                                    {
                                        Graphics2D g = (Graphics2D)strategy.getDrawGraphics();
                                        render(g);
                                        g.dispose();
                                    }while(strategy.contentsRestored());
                                    strategy.show();
                                }while(strategy.contentsLost());
                                if(count==100)
                                {
                                    count=0;
                                    cancel();
                                }
                            }
                        },2000,10);
        }
        public void render(Graphics2D g2)
        {
            x+=5;
            shot.setFrame(x,(x/5),5,5);
            g2.drawImage(face,0,0,null);
            g2.fill(shot);
            g2.drawLine(250,250,mx,my);
        }
        public void mouseClicked(MouseEvent event)
        {
            mx= event.getX();
            my= event.getY();
            t.schedule(new TimerTask()
                        {
                            public void run()
                            {
                                ++count;
                                strategy = canvas.getBufferStrategy();
                                do
                                {
                                    do
                                    {
                                        Graphics2D g = (Graphics2D)strategy.getDrawGraphics();
                                        render(g);
                                        g.dispose();
                                    }while(strategy.contentsRestored());
                                    strategy.show();
                                }while(strategy.contentsLost());
                                if(count==1)
                                {
                                    count=0;
                                    cancel();
                                }
                            }
                        },0,10);
        }
        public void mouseEntered(MouseEvent event)
        {
            //System.out.println("enter");
        }
        public void mouseExited(MouseEvent event)
        {
            //System.out.println("exit");
        }
        public void mousePressed(MouseEvent event)
        {
            //System.out.println("pressed");
        }
        public void mouseReleased(MouseEvent event)
        {
            //System.out.println("released");
        }
        public static void main(String[] args)
        {
            TRYBufferStrategy a = new TRYBufferStrategy();
        }
    }
    Fram:
    Java Code:
    import java.awt.event.*;
    import java.awt.*;
    public class Fram extends Frame implements WindowListener
    {
        public Fram(String str)
        {
            super(str);
            addWindowListener(this);
        }
        public void windowClosing(WindowEvent e)
        {
            System.exit(0);
        }
        public void windowClosed(WindowEvent e) {}
        public void windowDeiconified(WindowEvent e) {}
        public void windowIconified(WindowEvent e) {}
        public void windowOpened(WindowEvent e) {}
        public void windowActivated(WindowEvent e) {}
        public void windowDeactivated(WindowEvent e) {}
    }

  16. #56
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: game engine trouble

    Get rid of Fram, extend JFrame and add this one line:
    Java Code:
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    If you don't understand my response, don't ignore it, ask a question.

  17. #57
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    ikr... but thats unimportant at the moment, do you have any ideas about the previous post?
    Last edited by PRW56; 06-17-2012 at 03:08 AM.

  18. #58
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: game engine trouble

    It's important to me because I change every post to get rid of Fram.
    If you don't understand my response, don't ignore it, ask a question.

Page 3 of 3 FirstFirst 123

Similar Threads

  1. Easy Clip2D Game Engine now posted
    By rdjava in forum Reviews / Advertising
    Replies: 3
    Last Post: 06-03-2011, 06:24 PM
  2. Easy Clip2D Game Engine now posted
    By rdjava in forum Java Gaming
    Replies: 2
    Last Post: 06-03-2011, 06:18 PM
  3. Replies: 1
    Last Post: 06-02-2011, 10:29 AM
  4. Game Engine in Java, is it practical idea?
    By chan_nguyen in forum New To Java
    Replies: 2
    Last Post: 09-14-2010, 04:20 PM
  5. Crate Game Engine 20080323
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 03-25-2008, 05:50 PM

Tags for this Thread

Posting Permissions

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