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

2012/8/12

Pointing to offscreen object?

kiarocks kiarocks

2012/8/12

#
I want to have an arrow point to an offscreen object (I am using the unbounded world). I can make it point using turnTowards, but I can't make it stay on screen or move along the edge to get as close as possible. How would I make the tip stay on the edge of the world, yet get as close as possible to the ship?
danpost danpost

2012/8/12

#
In the Tip's act method, adjust its location (if outside the view window). If you 'move' it a sufficient amount toward the ship each act() (minimum 3, but preferably 4 or 5), then do the adjustment, It should work as you want. The adjustment being: if too far left, setLocation(getImage().getWidth() / 2, getY()); if too far right, setLocation(getWorld().getWidth() - getImage().getWidth() / 2 - 1, getY()); if too far up, setLocation(getX(), getImage().getHeight() / 2); if too far down, setLocation(getX(), getWorld.getHeight() - getImage().getHeight() / 2 - 1);
danpost danpost

2012/8/12

#
Another way is to set its location to the ship's location, then adjust as above.
You need to login to post a reply.