Archive for April, 2008
To my surprise i found the other day that, with the new AVM2, you can now access the content that you have drawn to the stage. It makes perfect sense, but i just assumed that it was locked. As a test, if you can draw something on the stage and then add the code
getChildAt(0).x = 100
This is reallly handy if you want to remove all the content from a clip, maybe move it into another, or add it dynamically to a child, then add effects. One note your drawing items are merged together (it doesnt preserve layers) unless there is a MovieClip between the layers. This is the only time that it splits layers into separate clips.
So you might think that rounded corners is easy in as3 with the new drawing tools. This is only so true if you don't want it dotted.
Thanks to senocular AS2 DashedLine.as which was easily converted to an as3 version DashedLine.as for as3 we can draw dotted lines and curves with actionscript. This left me with the task of using the quadratic drawing tools (no i didnt add a cubic curveTo to the Dashed line class) to draw circles (or quarters of circles, for the curners), which isnt the easiest, but i'll spare you the details and simply say, its done!
Using Draw.curvedBox(obj, offsetX, offsetY, width, height, cornerRadius) we can draw into any graphics object (whether it be a normal Sprite.graphics or a DashedLine Object). This is essential as the Dashed line tool doesnt actually give us a fill, so we might need to draw a normal shape for the background.
var dl = new DashedLine(this,1,5);
to draw a curved corner box with a fill, or solid outline, send in mc.graphics as the first attribute (or just the mc in as2)
So we can now do a box with curved corners in either AS2 or AS3 and in dotted or normal... phew!
Rendering a vector for every frame of a repeated animation (like in most games) take a lot of CPU. It takes even more CPU to have lots of complex characters on screen - many the same sprite.
cacheAsBitmap in flash is good, but only if you have static objects but recreates the bitmap data of an animation every frame, making it run even slower. The best solution is to cache each frame of an animation as a bitmapData, and then switch between them each frame. This works well until you have multiple instances of the same sprite - You dont want to pre-render the bitmap data and keeping it in memory many times, so it is best to keep a library of animations, and then reference the cached frames for each instance.
Another advantage of this technique is it seems to make use of Flash's new multi-core support. On a dual core CPU it can, if you push it, take almost 100% of resources. Trying it on a quad-core seemed only to take up two CPUs though. I guess this is both a blessing and a curse as you're more likely to grind a users system to a halt, even if they have multiple CPUs.
Animations copyright Nathan J. - http://www.scarygirl.com/
I've always wanted to use a Joytick with my Flash games.
A while ago I was working on small game for Lorial - in-store advertising for Biotherm - through a great company Eness. It was a simple "catch the falling objects with a timelimit game" made in Flash, but needeed to be controlled using a joytick as it had to be simple and easy to use for anyone walking through Myer.
After a little research I found the amazing program AutoHotKey. This lets you specify macros to do things like using a joystick as a mouse or keys, or pressing a combination of keys and starting a program. Using this amazing peice of software (Windows only sorry) and hacking around with some of their joystick input exampels it was easy to map joystick movements and buttons to the arrow keys and "A" on the keyboard, which were then read by Flash.
On a recent game I've been working on (Scarygirl) I've found that user testing on the keyboard really gets in the way of the gameplay itself, especially for those not used to games. It was a lot easier to hand them a Playstation 2 DualShock controlller attached via a USB converter and have an AutoHotKey script running that converted the D-Pad and buttons to input. The hardest part of this is finding which button on the controller relates to what input into windows. The easiest way I found to work with this was Start->Control Panel->Controllers and just writing down a list of buttons as I pressed them.
So yeah. Easy. And fun. Some games are just so much better with a good controller - just never let me catch you playing an FPS on a console!
I've been playing with JSFL a little recently. It was really hard to begin finding any resources on how to use it and those I did find were pretty sparse with information. So to help the community out I'm going to start posting my experiments, some useful, some only good for me, for everyone to take a look at, take apart and generally learn from.
The first one is one of the simplest. It lets you select all Elements of the same class on the stage. Simply select one of them, say a RadioButton, then choose the TMP - Select Same Class from the Commands menu and all other RadioButton instances should be selected.
We've finally nearly got our 40gb of MAME running- productivity boost! It took a while to figure out, but we finally have PS2 controllers to work - conected with a USB adapter. To run MAME with USB controllers on XP i've found:
- connect controllers & test that they work in the Control Panel > Game Controllers Panel.
- get MAME to create a .ini file
You need to run 'mame -cc' this can be done at the command prompt, or by making a .bat file
- Edit the 'mame.ini' file (should be created next to your mame.exe)
Change the line 'joystick 0' to 'joystick 1' - this enables joystick input
- Press tab when in MAME to get the key setup options.
- Rock out!!