Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 56
Like Tree1Likes

Thread: pixelperfectcollision

  1. #21
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,001
    Blog Entries
    7
    Rep Power
    20

    Default Re: pixelperfectcollision

    Check (and print) the cornerTopX/Y and cornerBottomX/Y variables and see if they are correct. The Image definitely isn't null (you might draw it to check whether or not it is empty).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  2. #22
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    123
    Rep Power
    0

    Default Re: pixelperfectcollision

    cornerTopX/Y and cornerBottomX/Y are correct. They give correct coordinates. Since 1 image is 8x1 pixels and the other is 80x132 then the difference between topx and bottomx must be 8. and it is. topy and bottomy difference must be 1 and it is 1. 2 arrays created have 8 slots. but for some reason all the members of botth arrays are 0 even when the collision is happening.

    and if i print out pg1 then i get somekind of weird line" java.awt.......pixelgrabber@6265" etc.

  3. #23
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,001
    Blog Entries
    7
    Rep Power
    20

    Default Re: pixelperfectcollision

    Quote Originally Posted by vastrolorde View Post
    and if i print out pg1 then i get somekind of weird line" java.awt.......pixelgrabber@6265" etc.
    Then printing the PixelGrabber doesn't give you any information; print the color values stored in the two arrays, pixels1 and pixels2 (after that PixelGrabber has grabbed the pixels). b.t.w. did you draw the Image? Was anthing visible in it?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #24
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,931
    Rep Power
    4

    Default Re: pixelperfectcollision

    Quote Originally Posted by JosAH View Post
    b.t.w. did you draw the Image? Was anthing visible in it?
    Check out #8 and #9. I also suggested it again later. Apparently the OP doesn't know how to use the painting methods. I should have said something then.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #25
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    123
    Rep Power
    0

    Default Re: pixelperfectcollision

    after pixelgrabber has grabbed pixels all tha values in pixels1 and pixels2 are 0. I have the painting method, but i dont know how to integrate it into the pixelperfectcollision code. i have tryed it, but doesent work.

  6. #26
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,931
    Rep Power
    4

    Default Re: pixelperfectcollision

    Since you are using BufferedImages have you considered using the getRGB method to get the integral value of the color. It is indexed by x and y. It might be easier than using pixelGrabber. I do not know how it compares in terms of efficiency.

    Here is a brief blurb on painting. Assuming you are using JPanel, override paintComponent(Graphics g). First call the super class method of the same. Then use the graphics context to draw the image. Check out the Graphics and Graphics2D API. Note: Most of the time Graphics can be cast to Graphics2D in Swing methods.

    Check out the tutorials in my signature on painting and other very useful stuff.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  7. #27
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    123
    Rep Power
    0

    Default Re: pixelperfectcollision

    Well i dont care that mutch about the color, it compares pixels from 2 different images and determs if they are overlaping. So its more like: are 2 non transparent pixels overlaping or not. I hope i understood your getRGB suggestion correctly :)

  8. #28
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,931
    Rep Power
    4

    Default Re: pixelperfectcollision

    You are grabbing the Color of the pixel in both cases. The alpha value which determines transparency is in the high order 8 bits.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  9. #29
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    123
    Rep Power
    0

    Default Re: pixelperfectcollision

    Java Code:
    Graphics g;
    		Graphics2D g2 = (Graphics2D) g;
    		
    		g2.drawImage(image, 0, 0,null);
    		g2.drawImage(image2, 80, 0,null);
    I added these lines into pixelperfectcollision. So why isnt it working. Those tutorials in you signature. THey helped a bit, but not enough.

  10. #30
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,001
    Blog Entries
    7
    Rep Power
    20

    Default Re: pixelperfectcollision

    Quote Originally Posted by vastrolorde View Post
    Java Code:
    Graphics g;
    		Graphics2D g2 = (Graphics2D) g;
    		
    		g2.drawImage(image, 0, 0,null);
    		g2.drawImage(image2, 80, 0,null);
    I added these lines into pixelperfectcollision. So why isnt it working. Those tutorials in you signature. THey helped a bit, but not enough.
    'it isn't working' is too vague; if no NullPointerException is thrown and you don't see an image, you can be sure the Image is completely empty (that explains all the zeros in your arrays).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #31
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    123
    Rep Power
    0

    Default Re: pixelperfectcollision

    ok i mught have used wrong words. Not compiling.

  12. #32
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,001
    Blog Entries
    7
    Rep Power
    20

    Default Re: pixelperfectcollision

    Quote Originally Posted by vastrolorde View Post
    ok i mught have used wrong words. Not compiling.
    And what did the compiler say about it? b.t.w. you do realize that the length of a thread is inversely proportional to the change that it ends succesfully?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  13. #33
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    123
    Rep Power
    0

    Default Re: pixelperfectcollision

    Java Code:
    C:\Users\Marko\Desktop\java>javac boss\*.java
    boss\Board.java:141: variable g might not have been initialized
                    Graphics2D g2 = (Graphics2D) g;
                                                 ^
    and why is it inversly propotional?

  14. #34
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,001
    Blog Entries
    7
    Rep Power
    20

    Default Re: pixelperfectcollision

    Quote Originally Posted by vastrolorde View Post
    Java Code:
    C:\Users\Marko\Desktop\java>javac boss\*.java
    boss\Board.java:141: variable g might not have been initialized
                    Graphics2D g2 = (Graphics2D) g;
                                                 ^
    You can't just define a Graphics g reference and use it. I suspect you don't know what you're doing; please follow the advice already given to you: read some tutorials on Swing and its painting model.

    Quote Originally Posted by vastrolorde View Post
    and why is it inversly propotional?
    Experience.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  15. #35
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    123
    Rep Power
    0

    Default Re: pixelperfectcollision

    I have read the tutorials on swing and its painting models, but im not getting antswers for my problems. They dotn explain the parts that i want to know about. I want to know, why must the Graphics g be in the function title or however its called. And the second big problem withthe tutorials is, that my native tongue isnt english. My language skills are on the c1 level, but my english doesnt have any spetsialisation, and in tutorials there are so many words and expressions that i dont understand. Dictonaries and translators wont translate the Sentences well enough, that i could getthe point of what its saying. If i wouldnt have this language problem, i probbly could solve this problem on my own. And there arent any competent guides in my language either. I understand that you are trying to point me into the right track with the suggestions and stuff. But some kinds of examples that would explain what excactly it is that you want me to do would bem ore than welcome. I know that this would probably take lot of time, but if possible, a example explaining the point would be awesome :)
    Last edited by vastrolorde; 06-11-2013 at 01:52 PM.

  16. #36
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,001
    Blog Entries
    7
    Rep Power
    20

    Default Re: pixelperfectcollision

    Fair enough; Swing uses one major rule: it decides what component(s) need to be redrawn, not you; when it decides a component (or part thereof) needs to be redrawn, the paintComponent( ... ) method of that component is (indirectly) called with a properly initialized Graphics object that can handle all drawing operations. Below you'll find a small image drawing panel; stick it in a JFrame somewhere so you can actually see what you're doing:

    Java Code:
    import java.awt.Graphics;
    import java.awt.Image;
    
    import javax.swing.JPanel;
    
    public class ImagePanel extends JPanel {
    
    	private Image image;
    	
    	public ImagePanel() { super(null); } 		// no layout manager needed
    	
    	public void setImage(Image image) { 		// set an image
    		
    		this.image= image; 
    		repaint();				// Ask Swing to repaint this panel
    	}
    	
    	public void paintComponent(Graphics g) { 	// Swing calls this method
    		
    		super.paintComponent(g);		// draw the background
    		if (image != null)			// if image present draw it
    			g.drawImage(image, 0, 0, this);
    	}
    }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  17. #37
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    123
    Rep Power
    0

    Default Re: pixelperfectcollision

    I got it painting. Now i realised how stupid i am not noticing this before :D.
    Pixelperfectcollision class gets the 2 images. But the pixels1 and pixels2 arrays are empty. I guess the pixelgrabber is not working properly.
    Last edited by vastrolorde; 06-12-2013 at 10:56 AM.

  18. #38
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,001
    Blog Entries
    7
    Rep Power
    20

    Default Re: pixelperfectcollision

    Quote Originally Posted by vastrolorde View Post
    I got it painting. Now i realised how stupid i am not noticing this before :D.
    Pixelperfectcollision class gets the 2 images. But the pixels1 and pixels2 arrays are empty. I guess the pixelgrabber is not working properly.
    Don't blame it on an ancient class, used by zillions of people; it is more than likely your own code that contains the error; what does the PixelGrabber.getStatus() method return? Is the PixelGrabber ready yet?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  19. #39
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    123
    Rep Power
    0

    Default Re: pixelperfectcollision

    Before grabpixel status is 0 and after grabpixel status is 19

  20. #40
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,001
    Blog Entries
    7
    Rep Power
    20

    Default Re: pixelperfectcollision

    Quote Originally Posted by vastrolorde View Post
    Before grabpixel status is 0 and after grabpixel status is 19
    Read the API documentation for the ImageObserver interface and see what those bit flag values mean.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

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