This site requires JavaScript, please enable it in your browser!
Greenfoot back
jackandjim
jackandjim wrote ...

2015/4/9

getX() and getY() when you got multiple objects of the same class

jackandjim jackandjim

2015/4/9

#
We want to make collisions between two objects of one class and we would need both coordinates for it... My question would be: How to get the coordinates of several objects of one class? I'd be happy to give you more information if needed. Thank you in advance, J&J!
danpost danpost

2015/4/10

#
That is no different than getting coordinates from two objects of different classes, Let us say we had an Actor subclass called Guy. Then, in the Guy act method:
Actor guy = getOneIntersectingObject(Guy.class);
if (guy != null)
{
    int guyX = guy.getX();
    int guyY = guy.getY();
    int thisX = this.getX(); // or 'int thisX = getX();'
    int thisY = this.getY(); // or 'int thisY = getY();'
    // etc.
You need to login to post a reply.