3

I am currently using JavaFX Pane and have a ball class (an Imageview) within it that I want to bounce off the edges of it like is detailed here however the minX of the Pane seems to get smaller as the ball goes off the edge of it.

It seems the Pane resizes to fit all the nodes added to it, meaning I can't ever check if the ball goes off the left side of the Pane. Is there a way to prevent this resizing or a better way to check the edges of the Pane?

Makori SM
  • 81
  • 5
  • 2
    work through a tutorial about how to use layouts - when stuck come back with a [mcve] demonstrating what's wrong – kleopatra Jan 02 '22 at 00:09
  • [bouncing ball app](https://gist.github.com/james-d/8327842) – jewelsea Jan 02 '22 at 00:44
  • “the minX of the Pane seems to get smaller as the ball goes off the edge of it” -> don’t let the ball go off the edge. – jewelsea Jan 02 '22 at 04:46
  • Another example: [breakout game](https://gist.github.com/jewelsea/910dae32ef6d1bd4257850031aefcba2) (more complex). – jewelsea Jan 02 '22 at 04:47
  • @jewelsea so from what you're saying/your second example I'm getting the impression that Panes always resize? As in there's no way to really get the bounds without just extracting them out into a second object at creation? – Makori SM Jan 02 '22 at 15:44
  • 1
    @MakoriSM No, that’s not what I think jewelsea is saying. If you check the current bounds of the pane when you love the ball, and just don’t move the ball outside those bounds, then the bounds should never change. – James_D Jan 02 '22 at 15:51
  • 1
    Read the links and try to implement it the same way. If you can’t do it, create and post a [mre] demonstrating the problem. – James_D Jan 02 '22 at 15:52
  • @James_D I'm able to do it in that way, but that's a different implementation to the one I proposed, one that only is necessary if my assumption that "you can't check the ball once it has gone off the edge because the Pane will always resize" is true. I want to know if there is no way to prevent this Pane resizing. – Makori SM Jan 02 '22 at 16:27
  • @MakoriSM “Move it and then move it back if it moved off the edge of the pane”, as compared to “move it only if moving it doesn’t move it off the edge of the pane” just seems like a terrible choice anyway. It’s not really possible to answer the question you’re asking without more information though. – James_D Jan 02 '22 at 16:30

0 Answers0