Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: javafx collision detection (simple)

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default javafx collision detection (simple)

    hello

    i have a question, i am making a simple game with javafx, and i want to use collision detection.
    i have got to nodes (circle1 and circle2) which move trough the scene. When they hit eachother
    i want them to disappear, but i have no idea how to manage this. I have been looking around on
    the internet, but it was way too difficult for me to understand or it was something too different
    from my project,
    i was hoping someone could help me out

    Thanks in advance

    Dirk

    --- Update ---

    I am sorry, i accidently posted in the wrong section.
    I thought i was in the right section, but apparently i was not.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: javafx collision detection (simple)

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Here's a thought. Read this tutorial that has a good discussion of collision detection and how to program it in JavaFX, and tell us what you don't understand about it. You might find this author's whole tutorial (starts here) and do that to cement what is being presented.

  3. #3
    Junior Member
    Join Date
    Aug 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: javafx collision detection (simple)

    How 'bout ".contains" or ".intersects" methods for your circles?

  4. #4

    Default Re: javafx collision detection (simple)

    Try something like this - it adds a flag so that the routine does not "forget" that a collision was detected:

    private void checkBounds(Shape block) {
    boolean collisionDetected = false;
    for (Shape static_bloc : nodes) {
    if (static_bloc != block) {
    static_bloc.setFill(Color.GREEN);

    if (block.getBoundsInParent().intersects(static_bloc. getBoundsInParent())) {
    collisionDetected = true;
    }
    }
    }

    if (collisionDetected) {
    block.setFill(Color.BLUE);
    } else {
    block.setFill(Color.GREEN);
    }
    }

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: javafx collision detection (simple)

    @priya456 This thread is 3 years old.

    Thread closed
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Collision Detection
    By Jobrien15 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 17th, 2013, 09:00 PM
  2. Collision Detection
    By Jobrien15 in forum Java Programming Tutorials
    Replies: 1
    Last Post: October 2nd, 2013, 08:46 AM
  3. Collision detection
    By Cutupangels in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 10th, 2013, 07:48 PM
  4. 2D Collision Detection
    By Cuju in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 3rd, 2010, 10:39 AM