Jul 23 2009

Whirled API: Setting Game Dimensions

Whirled is a somewhat interesting gaming platform backed by Three Rings, the makers of Puzzle Pirates. Games played on Whirled are Flash (.swf) files, which are played inside the platform’s wrapper which is itself a large swf file. Unfortunately, Whirled’s dev forums are located inside Whirled and have poor search functionality. Additionally, because Whirled itself is similar to an open MMO and every in game object is coded by someone in flash, many of the people on their forums are not focused on building games– they’re building toys and avatars and furniture.

That’s not a problem, but sometimes it is very difficult to find information about fixing simple problems. Particularly when the technique you need is one you haven’t run into before at all.

I recently began porting a game to Whirled which I had written as I did my other games, in AS3 with FlashDevelop and the Flex SDK complier. When I uploaded the game onto Whirled for testing, I found that although my .swf was correctly marked as being 600×500 pixels in dimensions, Whirled thought it was closer to 2000×800 because I had objects on flash’s stage which were out of bounds of the intended display area (generally objects about to move onto the display area).

I’ll freely admit this is probably bad practice. But in a general flash game deployment situation, it doesn’t matter because the game is being displayed in an embedded player whose dimensions are set by the web-page’s author.

After quite a bit of mucking about with scale and align settings, I discovered the concept of a dynamic mask and added this to my init function:

var Mask:Bitmap = new Bitmap(new BitmapData(ScreenWidth, ScreenHeight, true));
this.addChild(Mask);
Mask.x = this.x;
Mask.y = this.y;
this.mask = Mask;

The first line creates a bitmap the size of my display area, and the second adds it to the stage. The next two lines are specific to the Whirled platform. Because Whirled is itself a Flash movie, and is displaying your game as a movie inside itself, your game’s 0,0 point is not 0,0 in global coordinates. If left out, the mask gets applied from the origin of the flash player’s screen, which is going to be located under a chat window 200 pixels or so to the left of the left side of your game. The last line prevents your game from displaying objects outside the boundries of the mask. I’m sure there is a processing hit for applying a mask like this, but I didn’t have any noticable slowdown in gameplay.

If you’re running into a similar problem on Whirled you may wish to try this technique. I am considering adding a mask to my ‘normal’ version of the game as well, because having a mask prevents the game from looking bad if someone incorrectly embeds the game or links directly to the .swf.

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment