Page 1 of 1

Getting access to an instance of a tile on the map

Posted: 21 Aug 2009, 15:36
by lilshtz
Given x,y (and z?) coordinates, is there a way to return a tile object for that position on the map?

For instance:

var px:int = 10;
var py:int = 11;
var pz:int = 0;

var room:Room = sfs.getActiveRoom();
var tile:Tile = room.getTile(px,py,pz);

trace("show skins: " + tile.skins);

Hard to imagine this would not be provided. What am I missing?

Thanks in advance.

Posted: 25 Aug 2009, 07:19
by Lapo
Hi,
you can use the getObject() method from the OpenSpace instance and pass the name of the object.

The name parameter can be the name of any Skin defined in the OpenSpace Map Editor. The function returns a DisplayObject ( Sprite or MovieClip depening on what you used )

Posted: 25 Aug 2009, 14:02
by lilshtz
That makes sense if I want to get a skin, but what if I want to get a specific tile on the map, given coordinates, and see if it is walkable? That is the specific example of what I am looking to do.

thanks.

Posted: 25 Aug 2009, 14:10
by Lapo
From the official documentation there's nothing like this.
I am not aware of undocumented functions but I doubt they exist.
Bax is the lead developer of the project so he will be the best person to respond here. He will be back from vacation next week, so I'll let him answer.

By the way, can you better explain what you are trying to do exactly?
Once you have determined that a certain tile is walkable what would you do?

Posted: 25 Aug 2009, 21:37
by lilshtz
I am trying to 'wiggle' an avatar out of a certain spot in case they somehow get stuck. ideally I would like to get the avatar's tile, and then get the surrounding tiles. If walkable, teleport there.

right now I am trying to teleport to tiles, and if it does not work I know that that tile is not walkable, so I try to teleport to another tile. This works ok, but I would like to be more specific about it.

In addition I would like to get an avatars position, and then look at the skins on the tile above it (using my current x,y, and adding 1 to each) to see if an exit skin exists on that tile. I know that I can get the object for each one of these skins, but again this is not as explicit as getting the skins of a specific tile. Can one even get the tile that a skin is on based on the skin object returned from openspace?

Posted: 26 Aug 2009, 08:28
by Lapo
I am trying to 'wiggle' an avatar out of a certain spot in case they somehow get stuck. ideally I would like to get the avatar's tile, and then get the surrounding tiles. If walkable, teleport there.
Sorry I don't follow you.
Why would an avatar get stuck? Are there traps in your maps? :)
If a user can get in a location it should be able to get out... at least that's how we presume maps are created. Can you elaborate?
In addition I would like to get an avatars position, and then look at the skins on the tile above it (using my current x,y, and adding 1 to each) to see if an exit skin exists on that tile.
You can use Avatar Events.
For example you register your avatar for an ENTER_TILE event. Each time your avatar enters a new Tile you get an event with a reference to that object which you can use to identify exits and whatnot.

Check the docs for the AvatarEvent class under the com.smartfoxserver.openspace.events package

Posted: 22 Sep 2009, 17:18
by Paul Scherbak
Lapo wrote:From the official documentation there's nothing like this.
I am not aware of undocumented functions but I doubt they exist.
Bax is the lead developer of the project so he will be the best person to respond here. He will be back from vacation next week, so I'll let him answer.

By the way, can you better explain what you are trying to do exactly?
Once you have determined that a certain tile is walkable what would you do?
Yes, I have the same trouble. I do a bot for testing of loading for a server. The bot should be able to walk the room.
I use function moveMyAvatar to move a bot to a new position of a room, and I process event AvatarEvent.STOP_MOVEMENT to start to move a bot again.
Problem in that if to transfer in moveMyAvatar an impassable point, event AvatarEvent.STOP_MOVEMENT will not fired. Means it is necessary to check a point on passableness to a function call moveMyAvatar.
Now I can check up only a point in which there is my character, by function getCurrentTile().
Very much there is no similar function getTile(point).

I need this too.

Posted: 12 Oct 2009, 00:24
by isho
I need this too.

I can't believe it's not available, it seems so basic.