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

2016/10/30

I don't know how an actor can read a position from another one.

NymburkSRO NymburkSRO

2016/10/30

#
Delo delo =(Delo)getWorld().getObjects(Delo.class).get(0); public void getPosdelo() { int x = delo.getX(); int y = delo.getY(); System.out.println("x+y"); } What did I do wrong?
danpost danpost

2016/10/30

#
NymburkSRO wrote...
What did I do wrong?
Well, the first line is not within the method. This means it will execute only once, when the object is created. However, it will not yet be in any world and you should get a 'nullPointerException' when creating the actor. Now, as long as you ALWAYS have a Delo object in the world, and the 'getPosdelo' method is called from the 'act' method or a method called by the 'act' method, it should work as the first line within the 'getPosdelo' method.
You need to login to post a reply.