Results 1 to 4 of 4
Like Tree2Likes
  • 2 Post By gimbal2

Thread: Moving Objects

  1. #1
    Flopet17 is offline Member
    Join Date
    Mar 2014
    Rep Power

    Default Moving Objects

    Hello guys,
    Let's say we have a matrics of coordonates:
    (0,0) (0,10) (0,20)
    (10,0) (10,10) (10,20)
    (20,0) (20,10) (20,20)

    And we have a class that draws a rectangle of 10 pixel height and 10 pixel width at 0,0 coordonates
    And we want to move with the arrows the rectangle but not to go off the frame.
    The question is:
    How can I do that if I draw another rectangle, it knows where is the other object and they not collapse. And so on, they move, but not collapse, just touch and stop.

    Thank you

  2. #2
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Rep Power

    Default Re: Moving Objects


    You need to have an object model of your rectangle objects and whenever you move one object you have to check for collisions.

    I am quite sure that you will find a lot of descriptions about collision detection using Google. (But maybe you even want to follow a game tutorial that includes a collision detection. That way you also see an example how you could hold the data in your application.)


  3. #3
    Flopet17 is offline Member
    Join Date
    Mar 2014
    Rep Power

    Default Re: Moving Objects

    In the last 2 weeks I did that, searching on Google amd youtube, but couldn't figure out.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Rep Power

    Default Re: Moving Objects

    Rectangles are the easiest to pull off. Google "bounding box collision detection". You might also want to search for an article on the topic, I'm sure you can find one there.

    The Java Rectangle class even has all the methods you might need to be able to pull it off.

    Note: this is mostly a theoretical topic, you're not going to get very far if you google for Java code that does it for you. You have to understand this topic to be able to apply it.
    kneitzel and Flopet17 like this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Moving objects in paintComponent void
    By Scyth3 in forum AWT / Swing
    Replies: 1
    Last Post: 02-07-2013, 05:41 AM
  2. Replies: 10
    Last Post: 04-05-2012, 10:32 AM
  3. Moving Objects in an circlelair motion.
    By Thomask in forum Java Applets
    Replies: 8
    Last Post: 02-17-2011, 06:23 PM
  4. Moving objects
    By rsjava24 in forum AWT / Swing
    Replies: 1
    Last Post: 02-26-2010, 11:47 AM
  5. examples of moving objects
    By fred in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:06 PM

Posting Permissions

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