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

2012/2/1

getLocation

Gazzzah Gazzzah

2012/2/1

#
Hello, I'm a bit of a noob at greenfoot. Can someone explain to me how I can get the location of and object and set it as an int? For example, object "enemy" must get the location of object "player" and store it as int playerX and int playerY. Also say if object "tankTurret" finds the location of "tankBase" and moves straight to it. With the tank example, there may be more then one tank on screen at a time. Anyone able to help me out with this?
davmac davmac

2012/2/1

#
Hi Gazzah,
For example, object "enemy" must get the location of object "player" and store it as int playerX and int playerY.
Assuming you already have a reference to 'player' from your Enemy, then you can simply do: playerX = player.getX(); playerY = player.getY(); If you don't already that reference, then you have another problem to solve first (and from your second question, I suspect that's the case). First of all, take a look at one of the tutorials: http://www.greenfoot.org/doc/howto-1 (And perhaps the other tutorials too - see the "Documentation" page, link at the top). Once you've done that, come back and ask more questions. It generally works best if you post some code - even if you've got a big question mark in parts of it - since then people can directly suggest how you might modify it to achieve what you want to.
You need to login to post a reply.