Slick Forums
http://slick.ninjacave.com/forum/

Getting objects positions
http://slick.ninjacave.com/forum/viewtopic.php?f=17&t=5144
Page 1 of 1

Author:  AtomizerZero [ Thu Jun 21, 2012 1:07 pm ]
Post subject:  Getting objects positions

Hi, I'm currently trying to get an objects position when you click on it. On my map, i have 1 object layer with about 7 objects on.

I'm currently getting the list of objects like this:

Code:
for (i = 0; i < map.getObjectCount(0); i++) {
         for (j = 0; j < map.getObjectCount(0); j++) {
            if (i == 0) {
               System.out.println("i: " + i + " name: " + map.getObjectName(i, j));
            }

         }
      }


The output for this is:

Code:
i: 0 name: TV
i: 0 name: Chair
i: 0 name: Sofa
i: 0 name: Picture
i: 0 name: Pot Plant
i: 0 name: Pot Plant
i: 0 name: Dining table and chairs

Which is entirely correct.

Now, the problem i'm getting is, how am i supposed to get the x and y of the objects and store them for use later? doing a similar loop for the getObjectX and getObjectY doesn't seem to be giving me anything.

Any help would be great! Thanks

Author:  Khorne [ Sat Jul 21, 2012 11:30 pm ]
Post subject:  Re: Getting objects positions

hey, haven't worked with objectlayer yet but what do you actually mean by:
Quote:
doing a similar loop for the getObjectX and getObjectY doesn't seem to be giving me anything.

?

does it really return nothing or does it return smth but you dont know what to do with it?
because it should give you the x and y values of the object (dont know if they are the actual pixel coords or just the tile location).
maybe you have to calculate the pixel-x/y values with them (multiplying with the tile size)?

greets Khorne

Author:  antonio conte [ Sat Aug 04, 2012 1:25 pm ]
Post subject:  Re: Getting objects positions

Tried Using TiledMap::getObjectX() and objectY()? You could probably do this inside the same loop.

I've yet to use this class, but these methods uses the same params as TiledMap::getObjectName.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/