Archive for the ‘Flash’ Category

Blog jam and Plan Japan

Wednesday, March 25th, 2009

tokyo skyline

Over the last 2 years, I’ve focussed all of my efforts on learning Actionscript. More recently I’ve begun to learn how to use Flex. I think I’m now at the point where I’m comfortable enough using Actionscript to be able to do pretty much whatever I want. Flex still stumps me with some of its code juju, but I now feel confident in tackling its arcane magic head on now. This blog is, in a way, a chart of my progress in these things. Well, from now, I’ve decided to take a slightly different direction.

Along with the rest of the Flash speaking world it seems, I have decided to move into game development (yeah I know Flashers have always made games, but games on other platforms) – and I’m not just taking about games for a certain fruit based brandwagon. In order to do this I’m going to need to learn another programming language. After some thought I’ve plumped for C++. Why? Well, I wanted to cover as much ground as possible mainly. C++ is a language that will give me a good base for developing for the Nintendo DS, the Wii (via the rather excellent Unity3D), the iPhone and others. As far as I can tell, all of the above will require specific graphics and controller code, for example using Objective C for the iPhone graphics. However, I didn’t want to limit myself to an Apple specific language which, by all accounts, has been hit with the ugly stick a few times.

I also want to post more on my blog. There is a lot that goes on in my life besides writing code (but sometimes the code does rather take over) and I’d quite like to put that out somewhere. As I get older, I’m pretty sure my memory is going, so it’d be nice to be able to look back and realise that I did more than program 24/7! Someone also mentioned that they thought my blog didn’t have enough pictures on it, so more of that too.

I’m setting up a new blog over at my company Steamshift’s website which is here: my other blog which I’m going to reserve for posts about the day job, while this one is going to be more esoteric in its content :)

The last thing, which is pretty big, is that my family and I have decided to move to Japan. For those that don’t know me, my wife is Japanese and we’ve always thought it’d be nice to spend a few years in Japan while the kids are young. We planned to go in May, but the global money bunglers have managed to make sterling so weak I might as well use cheese as a currency. Since I planned to carry on freelance work for my UK clients and to rent our house out to cover our Japanese living expenses, this has obviously impacted my earning potential. We are still going to go, but it’ll just take a while longer.

So onwards and upwards, as they say.

First steps with Flint Particles

Friday, January 16th, 2009

I’ve been meaning for a while to have a look at Flint and so here are my first steps with it.

First off, I like the way it is arranged. It is incredibly modular. Whilst this probably has implications as far as optimisation (although it seems to handle a whole load of particles pretty nicely), it does mean that any kind of particle system can be plugged together easily.

There are 2 basic objects that need to be instantiated – an emitter and a renderer. There are a few different types of renderer, for different types – Bitmap, DisplayObject and Pixel.

Once you have your emitter created, then the behaviour is adjusted by adding 4 things.

Initialisers.
These are used when a particle is created, so things like colour, mass, size, image to use etc.

Actions.
These are applied to the particle every frame. Things like gravity, collisions etc.

Zones
This an area of the screen, commonly a point, line, rectangle or circle. Zones can be used for some initialisers, for example position and velocity. A Zone used for position will be used to randomly place a particle in that area. The velocity zone creates the velocity based on the time taken for the particle to travel from [0,0] to the randomly selected point. Zones can also be used as actions. For example, a DeathZone is an area that removes particles that enter (or leave) it, and a Jet zone is one that adds a velocity to the particle if it is inside.

Activities
These modify the behaviour of the emitter every frame, for example making it follow the mouse or rotating.

Most of these have a 2D and 3D counterpart.

Right. Enough explanation. Here’s the first experiment:
(Please note there is a bug (in my code) that occasionally comes up where the particles are duplicated endlessly. You have been warned!) This has now been fixed :)
(more…)

Rockin with the Brighton Massiv

Friday, November 21st, 2008

You wan freelance? We got freelance. (If you’re in Brighton (or London (or anywhere, it is nearly 2009 (where did that go?) now) ) which, let’s face it, you wanna be).

Presuming I haven’t lost you with all the nested brackets, I’ve been kindly linked to by a few people now on the list of the top Brighton Flash Developers. Clearly it would be rude not to do likewise…

Here’s my list in alphabetical order:

Designers/Animators

Charis Mystakidou (wiredportfolio.com)
Kristan Akerman (sting.co.uk)
Luke Hornsby (flamingpixels.co.uk)
Tim Frost (bullandgate.com)

Developers

Me (here and also my company steamshift)
Matt Pearson (actionscripter.co.uk)
Matt Sayers (soplausable.co.uk)
Neil Manuell (revisual.co.uk)
Nikos Chagialas (devgallery.com)
Richard Willis (richtextformat.co.uk)

There were some more, but I think they’ve all been employed by plugin-media :)

swc fix

Wednesday, November 19th, 2008

Seems I was right (well, let’s see shall we…) in my hypothesis regarding swcs in the same folder as the fla. In order to test this, I started up a new Actionscript project in FlexBuilder and created an assets folder. In Flash I opened a new fla, which I saved into the folder and then began to load it up with assets. At 32.4MB and 130 odd symbols (including videos, vector symbols, images and sounds) my swc finally broke and wouldn’t import into Flex properly. I then created a swc folder in Flex Builder and set the fla to import into that folder. Importantly, I also deleted the swc + swf from the assets folder. After recompiling the fla and rebuilding my Flex project, everything magically worked again.

I hope this helps someone out!

swcked witch

Tuesday, November 18th, 2008

Since my unbridled enthusiasm for swcs a few posts ago, I’ve been sharply brought down to earth about just how unreliable they are. I’ve come across a couple of different problems that just defy all logic. While I still think they are by far the best solution for projects where you want to have your assets compiled into the swf, there are some things that will make you want to stop doing Flash development and go take up pig farming instead.

1) Sometimes your swc will just fail. This seems to be in some way related to the number of assets in the fla, but not neccessarily. You’ll know you’ve got this one when the previously fine references to the swc classes suddenly break, as though it can’t find them. Richtextformat has got a full explanation of the “solution” to this problem over on his blog.

2) Your swf can’t find the document class anymore. I have an fla that held all the assets for my Flex based project. I’m compiling this to a swc and then using that as a library. All fine. However, the designer doesn’t have Flex, so he wants to compile directly from the Flash IDE. So, I set up the document class for him. However, when the fla is compiled, nothing appears. No errors, no traces from either the document class or the timeline. Nada. The problem was that I had left Export SWC on in the publish preferences. Unticking Export SWC did nothing however, it required the swc to be deleted. Then, it worked. All I can assume is that Export SWC was generating a duff swc, which in turn was breaking the swf.

The solution workaround hack I’m using is to have 2 flas. One is set up for compilation from the Flash IDE, the other a blank, unsaved fla (as per Mr TextFormat’s instructions) to generate my swc. This is a pain in the arse, let’s be honest. Every time the fla is updated, I have to refresh the swc fla assets and recompile. I guess I could write some kind of jsfl script to do it for me, but I’ve wasted enough time on this already :(

Anyway. It seems that the Export SWC command in CS3 is really broken. I’m going to try on CS4 and see if it’s been fixed. Fingers, toes, tentacles and any other prehensile appendages crossed.

[Update - It seems like this issue only occurs if you are building the swf/swc into the same directory as the fla. I've tried it with a couple of builds to outside the directory, and it seems to be ok - there might also be an issue if the fla is inside the Flex directory structure but I haven't confirmed this. More testing is needed...]

Dynamic Framerates

Wednesday, November 5th, 2008

One thing that I’ve started using in most of my projects where the processor could get hit heavily is a dynamic rendering system. This seems to be working really well, so I thought I’d share it.

I came across the idea from this post over at 8 bit rocket. The idea is pretty simple. A timer is set to run as fast as possible. Every time the timer executes, it runs a render cycle and a code cycle. It then checks how long the total cycle took and does 1 of 2 things. Either it sleeps for a certain amount of time, so that the swf doesn’t run too fast, or the next render cycle is dropped so the player can catch up. It’s a little more involved than that so if you want to know the finer details, head on over there.

I made some crucial adjustments to the code that’s presented there however. The biggest one was to make the code into a class, so that I could use it more easily. I’ve set up a system for registering renderers and updaters so they can be added and removed from the timer, and also added some events that get dispatched on render and update cycles. It works really well if you have an MVC setup, since the model and the view are already separate.

The source code is available here. Documentation after the jump.
(more…)

Lightwave -> Papervision3D

Thursday, October 30th, 2008

In this post, I’m going to go through how to get a textured model from Lightwave into Papervision3D. It’s really not as easy as I should be because of the lack of a collada exporter in Lightwave. The title should actually be more like: Lightwave -> wavefront obj file -> Blender -> dae file -> Papervision3D.

I use Lightwave for no other reason than I used to use it back in my Amiga days and since I rarely need to do any 3d work, there seems little point in learning another 3d package when I have so much else to learn :) They have a ‘discovery’ (ie free) edition too.

There are many, many pitfalls in this process, but once you’re aware of them, it doesn’t take long to do. I’m going to assume that you know nothing about Blender (as I did 8 hours ago) but do know how to use Lightwave. If you don’t know either, you might be better off either learning Blender straight off (or Maya). Props to Altered Egg for the details on what to do in Blender. He’s got pictures and stuff, if you need them :) I’m using Lightwave 9 and Blender 2.48
(more…)

Flash Flex Font Fudging

Tuesday, October 21st, 2008

Yesterday I spent quite a while trying to get some fonts to display correctly in a Flex Actionscript project. The method I normally use is the one I outlined in this post. This method is good because it allows you to embed only the characters you need and has always worked. Except yesterday.

The main difference as far as I could tell was that I was mixing Flex components and Actionscript text fields. The font was displaying in the Flex, but not the Actionscript. I had embedded the font using Flex’s CSS, so I thought maybe it wasn’t being passed over to the flash, so I embedded the font using the method above as well. Still no joy. I then removed the font completely from the Flex, in case it was screwing things up. Again, nothing. At this point I was getting pretty frustrated, as you could imagine. I went back over the Embedding Fonts technote and noticed that it said that only Truetype or bitmap fonts were supported. So I checked the font type. Sure enough, it was Truetype. About an hour later I decided to reinstall the font in case it was corrupted (it was showing fine in the Flex and in the Flash IDE, so I thought it unlikely). When I looked at the actual file in finder, it had the extension .dfont, which apparently is a datafork truetype font. Make no mistake, this is not supported by Actionscript.

So, in the end I installed a simple Truetype version and it worked straight off. No embedding needed in the Actionscript, just the CSS. I haven’t tried out the new font engine in Flex 4/Flash Player 10, but I really, really hope it doesn’t make you jump through quite so many hoops to display some text right.

Revised Cart Physics

Friday, October 3rd, 2008

Having read through Marco Monster’s car physics document (from this post) I thought I’d make some adjustments to the way my cars accelerate. Turns out that I had pretty much got it right, but there was one important factor that I hadn’t considered – air resistance. This is a big one because it incorporates the square of the car’s speed. This means that as the speed of the car increases, the resistance increases exponentially. Currently I have a maximum speed limit for the car, which is a bit clumsy and I’ve never really been comfortable with, as it’s another “magic constant”. With this method the car will eventually top out all on its own and I can remove a bunch of max speed tests. Following the jump, I’ll explain how I took the equations presented in the paper and put them into Box2D to provide something useful. I’m simplifying the model as presented in the paper, since I don’t really need it all (I’ve removed mass transference, gearing, torque ratios etc.) because I’m using carts. I might put in gearing at a later date, but I’d always rather having something working first and then change it if it isn’t fun enough :)
(more…)

Never sort, always compare

Friday, September 26th, 2008

I had an instance today where I needed to find the boundaries of a collection of points. All of the points were in an array, so I thought, “OK, I’ll do a sortOn for x and then get the top and bottom values and then do the same for y. This worked, but was really slow. After doing a few tests, I realised the quicker way was to loop through the array and compare to an initial value. An added bonus is that I only need to loop through the array once for any number of values. Here’s the code:


var xLo:Number =
var xHi:Number = points[0].x;
var yLo:Number =
var yHi:Number = points[0].y;

var len:int = points.length;
for (var i:int = 0; i < len; i++)
{
var pt:Point = points[i] as Point;
if (pt.x < xLo) xLo = pt.x;
if (pt.x > xHi) xHi = pt.x;
if (pt.y < yLo) yLo = pt.y;
if (pt.y > yHi) yHi = pt.y;
}