Posts Tagged ‘games’

New job

I have undertaken my new role at Avenue A|Razorfish and shall be going straight into games development and RIA/rich media production. Which has led me to look into the explosion of complex actionscript code that’s now in development. For example, 3D, physics, filters, animation sequencing. Pulling together this technology creatively is the challenge, as well as untapping it’s potential. That’s where the fun lies too.

└ Tags: ,

Tracking the mouse outside Flash part II

Today, let’s look at how to get a movieclip to point towards the mouse from a fixed location. This is a lot easier when tracking in one direction. For example, on my site, the TV is able to track the horizontal (x) coordinates of the mouse separate to the vertical (y) coordinates. All that happens is that one movieclip is nested in the other, both have a timeline, and the actionscript calculates a frame proportional to the position of the mouse for both movieclips respectively.

In a more recent project, it was an flv video that needed to track the mouse. Therefore, both x and y had to be tracked simultaneously. To achieve this it became necessary to establish the orientation, or angle of the mouse pointer in relation to the target. If we were to draw an imaginary triangle we can calculate the angle.

The three points to use are the mouse position, the target’s position and the point where the x value of the mouse hits the y value of the target, forming a right angle triangle. We can then establish the length of the adjacent and opposite sides of this triangle and use trigonometry to calculate the angle. In actionscript, inverse tan can be achieved with Math.atan(opposite/adjacent); After this, a little tinkering around is necessary. The result is in radians and needs to be converted to degrees.

Then the position on the timeline has to be worked out using a formula like this: Math.round((360/number of frames) * result). A final sprig of easing is the final touch for a very cool effect.

Magazine feature

Our company is featured in this month’s Develop magazine! It also features a photo of our team on games quiz night. Unfortunately for us, they published the results! :S

Also, the latest project we’ve been working on for the last six months is coming to fruition! Playsega Goes Live

Today is an exciting day, after months of sweat and tears and spitting up hairballs! Our new game, Meowcenaries goes live… cat on cat violence isn’t pretty, but it’s kinda cute. lolz!!

Game development

Recent projects have highlighted some of the most challenging and interesting issues in Flash development I’ve had to solve. For gaming, one key aspect is speed and memory management. Developers who are used to movieclips and tweening, which normally lend themselves so well to animation, soon discover how unwieldy these can become in a realtime game, like Meowcenaries.

In that game, not only are there over a dozen separate animated game objects moving around on screen at any time, but the speed of their movement is important. Add to this the fact that several of the levels are huge, which means lots of information stored at runtime, and the slowdown becomes apparent very quickly.

For Meowcenaries the solutions were varied, but key to maintaining the speed was ‘flattening’ the nested movieclip structure, and using the BitmapData class to copy flat images onto the screen. The advantage is that all the memory that would usually be reserved to store all those movieclips is released.

We also discovered that tweening, especially transformations, such as colour or transparency caused significant slowdown. This was due to the additional maths required for Flash to calculate the overall required colour for any given pixel where semi-tranparent colours are overlayed. We found the best way to keep the cool animations without the memory overhead was to pre-render them or ‘trick’ the eye. For instance, some animations are not tweened, they consist instead of a staggered set of keyframes representing the different states of the tween.

Also, the game was built in AS3 which introduces the issue of memory leaks – a problem that Flash developers, including me, did not really have to worry about in AS2. It soon became apparent that memory leaks could crop up in the unlikeliest places making debugging a serious issue.

After much hair-pulling a solution was found to speed up debugging. This was to use Flash CS4 to create a movie loading environment. Using the System.totalMemory property we could monitor the memory usage at any given time. A button could be pressed to load and unload the flash movie being tested. When the movie was unloaded System.gc() was called, which is only available in CS4. The advantage of this technique is that after a number of times hammering this button, it would become apparent if something was stuck in memory. Testing different modules of code made it much quicker to pinpoint where the problem was.

In summary, game development brings up many new challenges, some which seem to take you deeper and deeper into the rabbit hole. Luckily, the end result is very rewarding – improving gameplay is a very satisfying job.

└ Tags: , ,