Modify tiles walkability in OpenSpace (on-the-fly)

This post applies to OpenSpace 1.x, but may apply also to 2.x (I didn’t study it yet!).

One major issue for OS1 owners is controlling avatar’s movements all the time long. Full control over the avatar. All the methods and properties related to avatar movement and re-creation of the tile-map according to new settings are private, closed. You can’t access and modify them unless you purchase a source license.

But here we go with a custom solution, which may be helpful for you in some situations as it was for us. As there is no available method to prevent avatar movement (ie, the user clicks in a tile and the avatar walks there in despite of what you say), the only solution is preventing user clicks!

Simple, not smart, but working solution.

And how in hell you do that? Also simple: place a transparent-clickable movie-clip in the tile, so it catches user clicks and nulls them. Just iterate over OpenSpace.getChildAt(0)’s children (the tiles) and do the job.

And now a few hints, as the situations are very different depending on your needs…

You can’t moveMyAvatar() or teleportMyAvatar() to the current tile –> this way you can’t prevent avatar movements! So, before user clicks, you must evaluate and decide if the avatar can walk (click, if you use the suggested workaround).

If you can’t decide prior to user’s election if he can walk/click, then you must evaluate after he clicks and starts walking. In that situation, take into consideration the previous paragraph. As you can’t moveMyAvatar() or teleportMyAvatar() to the current avatar’s coordinates (as coming from getCurrentTile()), move or teleport the avatar to a different tile.

There is a variety of events you can use to evaluate your conditions (ENTER_TILE, TILE_SELECTED, etc.), so most probably you will find some solution to your headache 😉

EDIT: Appart from the exposed method, still valid, would be nice to take a look to the following approach: dispatch a first moveMyAvatar() to a fake tile, so OpenSpace registers as current-tile the next one in the pathfinding, the issue a new moveMyAvatar() to the current (real) one.

Advertisement

No scrolling maps in OpenSpace

Seems this is a FAQ for many OpenSpace users and it has been answered many times in their support forums. There isn’t support for no-scrollable maps in version 1.x of OpenSpace and it has been announced as a new feature for the incoming version 2.

In the mean time, while in the middle of the development of qilania, we found a workaround. Basically, you must attach the AvatarEvent “AVATAR_CREATED”, then call the method “centerViewOnTile”. You must make sure, though, that it exists a tile in the related position, so SmartFox/OpenSpace can find it using the z-index, which seems a requirement for “centerViewOnTile” to work. Sample code:

// os is the instance of the OpenSpace component in the stage
os.addEventListener(AvatarEvent.AVATAR_CREATED, onAvatarCreated)

function onAvatarCreated(evt:AvatarEvent):void {
	var pos:Object  = {px: 12, py: 12, pz:0};
	os.centerViewOnTile(pos);
}

You can know which tile you wish the viewport centered-in just making rollover in the map editor of the OpenSpace Editor. As stated, make sure there is a tile in such position of the tilegrid (being walkable or no walkable) by looking for the “z” property (close to x and y).

Appart from this, we created a background which must fit in the tilegrid (so, be smaller than the grid).

You must know as well that some actions of the avatar, such as teleportation, will fire “centerViewOnMyAvatar” (which will move the viewport), so immediately after the teleportation you must use again the “centerViewOnTile” method.

Most probably it would do the trick using a zoomed map (documentation says that using zoom will disable map auto-scrolling), but that would make the development process (basically illustration) a bit more complicated than it is already.

But there are more workarounds for sure, and you can find various in the support forums of OpenSpace.

Hello world!

Welcome to my personal blog about Qilania, the educational MMORPG for kids which will be born in 2010, where I act as product manager.

This will be a very interesting project, not only for its nature, but for the great amount of technologies used in it: SmartFox Pro Server and OpenSpace, PHP, MySQL, Flash and Flex, Java and AppleScript (in order to automate lots of tasks).

Stay tuned!