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

2018/2/6

Non static method in static context

Paul12345 Paul12345

2018/2/6

#
I'm trying to add an object in the world (in a specific case) , next to another object.The problem is getting the reference object coordinates. I can't use getX() and getY() directly since they are non static methods.
danpost danpost

2018/2/6

#
If only one of the type of object you need the coordinates of are in the world, you can use:
Actor actor = (ClassName)getObjects(ClassName.class).get(0);
int x = actor.getX();
int y = actor.getY();
If using this in an actor class prefix 'getObjects' with 'getWorld().'.
You need to login to post a reply.