How to move the object to the position of mouse(opengl?

Help with moving an object in Java?

  • Hello all, Could someone give me some advice on how to tackle this problem please - thank you in advance. So basically I have a program that paints a simple object image. There are 5 of these objects altogether and different classes and methods have been set up to do this and this works correctly. The program currently also asks the user if they would like to change the colour of this object shape, and which shape they would like to change (user inputs a number 1-5) then the program will change the colour of this shape. But the new task is for the user to input a number (1-5) to which shape they would like to MOVE position of. Any ideas on how this would be done? Would there need to be different methods for changePositionX, changePositionY? The user needs to input the X and Y co ordinates and then this will move the selected shape to its NEW position in the current JFRAME. Thank you, if any code is needed I will paste it in.

  • Answer:

    Obviously, you need a hierarchy so all your shapes have the same methods. If we have abstract class Sprite class Star extends Sprite class PolyBall extends Sprite class Ellipse extends Sprite // and so on, then from an array of Sprite[] sprites; for( int i = 0; i< sprites.length; i++ ) { Sprite selected = null; if( userInput = sprites[ i ].getID(); selected = sprites [ i ]; break; } moveMySprite( selected );

Oddsocks at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.