darren-w-
asked on
Detecting edges of frame, bouncing balls
Hi,
I'm working on assignment, I'm trying to get a unfilled circle to bounce around the inside of a jframe, I'm using the usual rules that if the balls pos x/y are under 0 to reverse the direction and if they are over the frames width - Radius to do the same, but I'm still having the problem where the circle goes well beyond the bottom and and more than half the way off the right.
I've looked at many examples and they all seem to use the same method as I'm doing? I'm not using threads.
Can anyone offer any clue to what is wrong. Don't have code to hand at present; but is this a typical problem.
Darren
I'm working on assignment, I'm trying to get a unfilled circle to bounce around the inside of a jframe, I'm using the usual rules that if the balls pos x/y are under 0 to reverse the direction and if they are over the frames width - Radius to do the same, but I'm still having the problem where the circle goes well beyond the bottom and and more than half the way off the right.
I've looked at many examples and they all seem to use the same method as I'm doing? I'm not using threads.
Can anyone offer any clue to what is wrong. Don't have code to hand at present; but is this a typical problem.
Darren
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Make sure the content pane of the frame has the same dimensions as the frame itself. Its possible, although not likely, that the content pane is larger.
ASKER
Found the problem, a superclass had methods that defined the available height, and that sorted it, I've been reading the article further and it goes into how objects bounce against another ie not at perpendicular or horizontal angles.
I cant quite get to grips with how it works, assume its a bit of trigonometry, is there an easier way of getting the correct angle based on x,y values?
D
I cant quite get to grips with how it works, assume its a bit of trigonometry, is there an easier way of getting the correct angle based on x,y values?
D
Can you elaborate a little bit on your question about x and y and angle?
ASKER
The link was very useful