Results 1 to 4 of 4
  1. #1
    Naxix is offline Member
    Join Date
    Jul 2011
    Posts
    13
    Rep Power
    0

    Default Makeing a border - Y axis bugging? FIXED

    Hello, so i'm trying to make a basic border structure for a object, which then should be bounced away when hitting the border. But for some reason i find the Y-axis bugging me alot, i tried changeing my code alot, but each time it keeps doing the same. When the object reaches the top border (and should be bounced away) it keeps going out of sight, and comes back a moment later.

    This is the code i have so far.

    Define the border coordinates (The applet size is 400x400):
    Java Code:
        public int Leftout = 30;
    	public int Rightout = 370;
    	public int Topout = 370;
    	public int Bottonout = 40;
    The code that checks if the object is out of the "border"
    Java Code:
    	public boolean isOut(){
    		
    		if(x_pos > Rightout){
    			
    			speedx = (rand.nextInt(2)+1)-4;
    			return true;
    			
    		}
    		else if(x_pos < Leftout){
    			
    			speedx = rand.nextInt(2)+1;
    			return true;
    		}
    		else if(y_pos > Topout){
    			
    			speedy = (rand.nextInt(2)+1)-4;
    			return true;
    		}
    		else if(y_pos < Bottonout){
    			
    			speedy = rand.nextInt(2)+1;
    			return true;
    		}
    		else return false;
    		
    	}
    I think the problem is here somewhere, i suspect the "speed" randoms.
    speed is just how much to move on X and Y axis, per 20 milliseconds.

    Regards Naxix
    Last edited by Naxix; 10-15-2011 at 08:20 PM. Reason: I got it working

  2. #2
    kraigballa is offline Senior Member
    Join Date
    Oct 2011
    Posts
    115
    Rep Power
    0

    Default Re: Makeing a border - Y axis bugging? (Applet)

    Well, if x == any of those values (meaning right on them) wouldn't it work just how you described?

  3. #3
    Naxix is offline Member
    Join Date
    Jul 2011
    Posts
    13
    Rep Power
    0

    Default Re: Makeing a border - Y axis bugging? (Applet)

    I'm not sure i know what you mean, right now it seems that the top border, is around 50 pixels out of the window?

    EDIT: I got it working, i think my other class went in and changed the border for some reason.
    Last edited by Naxix; 10-15-2011 at 08:20 PM.

  4. #4
    kraigballa is offline Senior Member
    Join Date
    Oct 2011
    Posts
    115
    Rep Power
    0

    Default Re: Makeing a border - Y axis bugging? (Applet)

    I was just saying that is you use x_pos > Rightout, then you as I'm sure you know x_pos can equal Rightout.

    However, I'm just curious if you have the Random object instantiated?

    Java Code:
    Random rand = new Random();

Similar Threads

  1. help needed on makeing a progres bar
    By Dumisan in forum AWT / Swing
    Replies: 0
    Last Post: 02-20-2010, 11:20 AM
  2. Set border
    By anilkumar_vist in forum New To Java
    Replies: 1
    Last Post: 02-06-2010, 12:25 PM
  3. Makeing a dialog not steal full focus
    By Drun in forum SWT / JFace
    Replies: 3
    Last Post: 12-18-2009, 07:54 PM
  4. how can create border
    By yuen in forum AWT / Swing
    Replies: 6
    Last Post: 11-08-2009, 12:42 PM
  5. Border with LestCellRenderer
    By Gajesh Tripathi in forum AWT / Swing
    Replies: 5
    Last Post: 06-02-2009, 07:59 AM

Posting Permissions

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