Flash games development

Coders forum. Discuss techniques, swap code snippets, ask for help etc. relating to all forms of software development.
Post Reply
User avatar
sack
Baaaaaaa!
Baaaaaaa!
Posts: 7077
Joined: Fri May 10, 2002 4:13 pm 0
XBL Gamertag: evilgopher
PSN: sixFiveOhTwo
Location: Rijswijk, The Netherlands
Contact:

Flash games development

Post by sack »

I've been taking a look at Actionscript 3 and it looks like everything I need to put a game together is in there without making my brain bleed too much so I reckon I might port my platform game stuff from C++ to actionscript.

First question... what do people reckon is an Acceptable size for a flash game? Obviously smaller is better but it's always going to be a tradeoff so I wondered what people think is acceptable or if there's anyone in the know with facts and figures.
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Flash games development

Post by Dio »

Is there a platform for writing this stuff without spending hundreds of quid?
User avatar
pogo
Sheepie Whore
Sheepie Whore
Posts: 14180
Joined: Tue Sep 10, 2002 8:28 pm 0
Yahoo Messenger: BrassSparrow
Location: County Durham

Re: Flash games development

Post by pogo »

Dio wrote:Is there a platform for writing this stuff without spending hundreds of quid?
Yes, e.g. FlashDevelop. See also here. As for size it's up to you, but if you want to upload it to game web sites there are limits. E.g. Kongregate I think is limited to 700 pixels wide, to allow space for their chat system, and about the same height so say 700 height.
User avatar
sack
Baaaaaaa!
Baaaaaaa!
Posts: 7077
Joined: Fri May 10, 2002 4:13 pm 0
XBL Gamertag: evilgopher
PSN: sixFiveOhTwo
Location: Rijswijk, The Netherlands
Contact:

Re: Flash games development

Post by sack »

D'oh... I should've specified.

I was thinking of something like 640x400 for the physical dimensions (because it seems to be a common size and close to VGA) - but I was asking about the download size
User avatar
_TinOmen_
Baaaa!
Baaaa!
Posts: 745
Joined: Wed Feb 12, 2003 10:52 pm 0
Location: Stockholm, Sweden
Contact:

Re: Flash games development

Post by _TinOmen_ »

I have found that one of the best sources on Flash-game development is the forum at FlashGameLicense, which is a great site that helps you auction your game to game-portals.

Most sites want your game to be a single swf-file so dynamic loading is usually not an option. I made a game that was 3mb and that was no problem, I don't know the upper limit that the portals accept though.
User avatar
failrate
Baaaaaa!
Baaaaaa!
Posts: 2354
Joined: Sun May 23, 2004 6:54 am 0
Location: Sandy Eggo
Contact:

Re: Flash games development

Post by failrate »

Re: free development platforms, the Flex SDK (free version) comes with the mxmlc compiler that is entirely sufficient for building a full game. This is good if you're a codemonkey, like me, who doesn't like mucking about with Flash's IDEs. http://www.adobe.com/products/flex/flexdownloads/

Also, even though it is guaranteed to make your eyes bleed, the Adobe Alchemy project makes it possible to compile some C++ libraries straight into AS3-accessible libraries. To be honest, though, for most games it's just easier to rewrite it in AS3 than muck about with Alchemy. Neat idea, tho.
User avatar
pogo
Sheepie Whore
Sheepie Whore
Posts: 14180
Joined: Tue Sep 10, 2002 8:28 pm 0
Yahoo Messenger: BrassSparrow
Location: County Durham

Re: Flash games development

Post by pogo »

failrate wrote:Also, even though it is guaranteed to make your eyes bleed, the Adobe Alchemy project makes it possible to compile some C++ libraries straight into AS3-accessible libraries. To be honest, though, for most games it's just easier to rewrite it in AS3 than muck about with Alchemy. Neat idea, tho.
It's more than just neat: people are seeing speed ups of a factor of 10 in C++/Alchemy vs AS. Here's the app with source to prove it. It's just one example but it's a telling one, as it's one of the particular bottlenecks of AS. Elsewhere someone has ported Doom to Flash 10 using it.

I don't know if it will take off: you need C++ and AS skills, as well as the time to write a lot of code (no point just porting a few routines to C++ because of the slow interface). But it makes a lot of things possible if Flash that just weren't feasible before. Emulators and ports of other old games for example.
User avatar
sack
Baaaaaaa!
Baaaaaaa!
Posts: 7077
Joined: Fri May 10, 2002 4:13 pm 0
XBL Gamertag: evilgopher
PSN: sixFiveOhTwo
Location: Rijswijk, The Netherlands
Contact:

Re: Flash games development

Post by sack »

that's alright because I'm pretty handy with C++ and I have most of the game written that way anyhow - just need to port it to AS or work something else out.
User avatar
The Bag
Baaa!
Baaa!
Posts: 343
Joined: Sun Jan 26, 2003 5:44 pm 0
Location: Guildford

Re: Flash games development

Post by The Bag »

A pretty good games with Flex tutorial - http://www.brighthub.com/internet/web-d ... 11010.aspx
User avatar
sack
Baaaaaaa!
Baaaaaaa!
Posts: 7077
Joined: Fri May 10, 2002 4:13 pm 0
XBL Gamertag: evilgopher
PSN: sixFiveOhTwo
Location: Rijswijk, The Netherlands
Contact:

Re: Flash games development

Post by sack »

okay... I've got a platform game-type thing running in flash (pretty much a port of some C++ code I had lying around, tidied up a bit) but I've got a problem.

initially it was running at a decent rate, and then slowly dying away, getting slower and slower with task manager showing the browser to be taking up more and more memory so I'm assuming it was leaking memory. The speed of the leak seems to be linked to the framerate, so it's definitely a per-frame leak.

The flex profiler doesn't show any memory leakage - the graph just shows everything being allocated when the game starts and nothing more. As far as what is allocating how much memory the profiler shows all the background stuff flex does and then just lumps my entire game into one entry with no further detail so to coin a phrase it's absolutely fucking useless.

after double checking I'm not doing any stupid memory allocation in the frame loop it's the same, just leaking a lot slower now, sometimes it doesn't leak at all. what does happen though is after a short while the framerate hits the floor as the garbage collector kicks in (at least I assume it's that because the memory usage drops in the profiler around this time) and it never really recovers.

so... I'm allocating everything upfront and my frameloop is pretty deterministic and doesn't vary much so the speed should be pretty constant but it fluctuates quite a bit and the garbage collection is crippling things.

Anyone got any clues as to what the hell I should be doing to avoid these problems?
User avatar
pogo
Sheepie Whore
Sheepie Whore
Posts: 14180
Joined: Tue Sep 10, 2002 8:28 pm 0
Yahoo Messenger: BrassSparrow
Location: County Durham

Re: Flash games development

Post by pogo »

That sounds tricky. When it happened to me early on I thankfully did not have much code - mostly some AI code which I wrote early as it was the riskiest/potentially most expensive bit of code. Every time I hit a button to trigger the code it got slower. I made some key data persistent, so it was allocated once at startup and never released, and the problem went away.

So all I can suggest is look at your code for likely causes of memory leaks. Flash uses a garbage collector, so in general you just stop referencing stuff and it gets released. But my experience suggests that even stuff you no longer need can hang around, maybe if it's a more complex structure such as a linked lists with internal references.

I just searched and found this

http://www.nbilyk.com/flash-garbage-collection

Which has some tips and a couple of links, which I've bookmarked myself for future reference as I know this will come back to bite me at some point.
User avatar
Orava
Sheepie Whore
Sheepie Whore
Posts: 12698
Joined: Sat Mar 13, 2004 12:13 am 0
Location: The West Country

Re: Flash games development

Post by Orava »

failrate wrote:Re: free development platforms, the Flex SDK (free version) comes with the mxmlc compiler that is entirely sufficient for building a full game. This is good if you're a codemonkey, like me, who doesn't like mucking about with Flash's IDEs. http://www.adobe.com/products/flex/flexdownloads/

Also, even though it is guaranteed to make your eyes bleed, the Adobe Alchemy project makes it possible to compile some C++ libraries straight into AS3-accessible libraries. To be honest, though, for most games it's just easier to rewrite it in AS3 than muck about with Alchemy. Neat idea, tho.
Flex is lovely if you need any web interaction, however you need to accept a few hundred kB penalty for the libraries. It lets you optimise fairly well so mostly only classes required are included, but even then there is some overhead.

Eclipse with the Flex plugin is a good alternative for Adobe stuff - not free though.
Holier than thou
User avatar
KlaxonCow
Baaaaaaa!
Baaaaaaa!
Posts: 8447
Joined: Fri Dec 13, 2002 3:46 am 0
Location: A large grassy field.

Re: Flash games development

Post by KlaxonCow »

Orava wrote:Flex is lovely if you need any web interaction, however you need to accept a few hundred kB penalty for the libraries.
Those libraries are only necessary if you're using the MXML UI components and the like - but most games can quite happily live without that (indeed, would prefer to handle their own UI, so that it can be made to fit the game's visual style, exactly so that it doesn't look like a bunch of ugly and clunky OS buttons) and it's quite possible to compile a pure AS3 file directly into a SWF with the compiler, completely ignoring the MXML stuff entirely.

I notice that the tutorial that "the bag" pointed to, doesn't seem to realise this and uses an MXML file to house the ActionScript as well:
The Bag wrote:A pretty good games with Flex tutorial - http://www.brighthub.com/internet/web-d ... 11010.aspx
But if you stick something like this into a "Test.as" file:

Code: Select all

package
{
    import flash.display.Sprite;

    [SWF(width='640', height='480', backgroundColor='#000000', framerate='25')]

    public class Test extends Sprite
    {
        public function Test():void
        {
              // code goes here.
        }
    }
}
...and then pass that to the MXML compiler, it'll spit out a SWF of only around 550 bytes.

Note that the main class in the file has to have the same name as the file itself (i.e. because the file is "Test.as", then the class inside it is "Test") - this is basically just so the compiler knows which one of your classes (as you could have many of them inside your package) is the main class that should be instantiated automatically to get your SWF going.

The "[SWF]" meta tag there is actually completely undocumented in the Flex docs (well, if you're using the "livedocs" online, one of the Flex team - realising the omission after publication - has added some basic information about it as a comment to the "metadata tags" page, but if you downloaded the documentation for offline use, you won't have those comments and will find that the tag just isn't mentioned at all anywhere in the docs. Ahem, a slight cock-up there, Adobe).

It also suffers from a small bug. It only works when placed after the imports. If placed before any imports, the compiler acts as if it isn't there. So, stick all your imports at the top then slot the [SWF] tag in below that (as shown) then it should work just fine. Ahem, another slight cock-up there, Adobe.

You can use this tag to specify the various properties - size, background colour, frame rate, etc. - in the pure AS code, which you'd normally use the Flash IDE / an MXML tag to set otherwise (meaning that you now don't need to actually use MXML or any IDE to get it working).

You can use the "[Embed]" tag in order to embed graphics and sounds into the SWF file directly (this is slightly awkward, simply because the [Embed] tag embeds files as raw octet streams (typed as just "Class") and you therefore need to "cast" them as a "SoundAsset" or "BitmapAsset" to get Flash to see them as sounds or bitmaps, so you can use them. Awkward, but not difficult. This stuff, though, is actually explained in the Flex documentation, so read that for more details).

These minor things out of the way, you can then code directly in AS3, ignoring the MXML stuff entirely.

I wrote a little trip-a-tron-alike / colourspace-y thing as a "proof of concept" to test this stuff out (see file attachment), and it falls out of the compiler at only 1.6KB or so - but I'm making use of sprites, bitmaps, filters, matrix and colour transformations, which is a fair list of imports and over a 100 lines of code. Doesn't seem to inflate the SWF file size at all, if you stick to the basic flash imports (which I presume are essentially all built into the player itself).

(You'd be hard-pressed to get any programming language to kick out this kind of code in only 1.6KB - if you use the Flex stuff in the right way (i.e. ignore the MXML entirely and just use it as an AS3-to-SWF compiler) then you can get perfectly lean and mean SWFs, making it a perfectly decent potential platform for coding games. You've just got to know a tiny bit of "voodoo magic" to get the compiler to spit out what you want. It's also entirely free to do things this way.)

Move the mouse over the Flash window to control the cursor (which is mirrored on both the X and Y axis).

Draw shit and it gets blurred and zoomed and cycled through different colours. Looks quite nice, really, considering how essentially simple the code for it was.

Enjoy! :D
Attachments
Trippy.zip
(SWF file stuck inside a ZIP, because the forum doesn't directly allow attachments with the SWF extension.)
(1.79 KiB) Downloaded 59 times
"Words ought to be a little wild - for they are assaults of thought on the unthinking."
- John Maynard Keynes
AdemoN
Posts: 17
Joined: Thu Oct 26, 2006 12:03 pm 0
Location: Gosport

Re: Flash games development

Post by AdemoN »

KlaxonCow wrote: ...

But if you stick something like this into a "Test.as" file:

Code: Select all

package
{
    import flash.display.Sprite;

    [SWF(width='640', height='480', backgroundColor='#000000', framerate='25')]

    public class Test extends Sprite
    {
        public function Test():void
        {
              // code goes here.
        }
    }
}
...and then pass that to the MXML compiler, it'll spit out a SWF of only around 550 bytes.

Note that the main class in the file has to have the same name as the file itself (i.e. because the file is "Test.as", then the class inside it is "Test") - this is basically just so the compiler knows which one of your classes (as you could have many of them inside your package) is the main class that should be instantiated automatically to get your SWF going.

The "[SWF]" meta tag there is actually completely undocumented in the Flex docs (well, if you're using the "livedocs" online, one of the Flex team - realising the omission after publication - has added some basic information about it as a comment to the "metadata tags" page, but if you downloaded the documentation for offline use, you won't have those comments and will find that the tag just isn't mentioned at all anywhere in the docs. Ahem, a slight cock-up there, Adobe).

...
Awesome! I never knew about this! Cheers KlaxonCow!
User avatar
KlaxonCow
Baaaaaaa!
Baaaaaaa!
Posts: 8447
Joined: Fri Dec 13, 2002 3:46 am 0
Location: A large grassy field.

Re: Flash games development

Post by KlaxonCow »

AdemoN wrote:Awesome! I never knew about this! Cheers KlaxonCow!
Yeah, as I mentioned in the post, Adobe's own documentation about being able to do this is effectively near non-existent - so I thought it was worth going into some of the details of how to get it working, because the fact that it can even be done is not really even signposted by Adobe themselves at all. Let alone explained too clearly. :roll:
"Words ought to be a little wild - for they are assaults of thought on the unthinking."
- John Maynard Keynes
Post Reply