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

Flash bitmap filters (ie: DisplacementMapFilter, perlinNoise) and CPU usage

I was looking for a way to animate water in qilania (our virtual world) and I found some quick code using the DisplacementMapFilter and perlinNoise, which seems very realistic for our traditional way to animate stuff (more like cartoons), but is a quick and acceptable hack which can actually fit with our design and will save some time to the illustrator in chief.

But seems that kind of scripted animation (should say more “effect” than animation) consumes so much CPU, specially in the SmartFox/OpenSpace environment which uses to be 30fps by default.

After some researching and looking for alternative methods, we decided the fractal noise was looking so nice after all, but we needed some way to save some CPU and RAM for the end user, specially looking towards old machines and architectures. And we found a way to decrease it. This is a very simple tip: decreasing the frame rate. We did it this way (follows pseudo-code):

this.addEventListener(Event.ENTER_FRAME, go);
var nvar:int = 0;
function go(evt:Event):void {
	nvar++;
	if(nvar%3==0){
		// perlinNoise stuff...
	}
}

This way we reduced the filter to 1/3 (that is 10fps for a 30fps project), which saves more than 50% of the CPU at execution time.

It’s still so much, but minimum enough and, after all, we don’t have water in all our maps!

Hope this simple idea can help someone in a future: the simple, the better 😉

OpenSpace 2.0b2

Recently released.

http://www.smartfoxserver.com/forums/viewtopic.php?t=6734

I have the piece of gold in my inbox, but won’t take a look until it’s final or close to final, as we can’t use it in a production environment, specially when this environment is still in the middle of the development process.

This version contains lots of new features customers asked for in the past, such as centerViewOnCoords, getAllSkinsByName, getMyAvatarCurrentTile or setting some parameters at run time, such as animationTime at avatar creation time.

Hopefully the documentation and other details will be ready very soon and maybe we will be able to introduce some interesting hacks in the current version of Qilania.

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!