Log in
Please log in or register.
Pages: [1] 2
  Print  
Author Topic: Best Flash Tricks?  (Read 1818 times)
Adam Atomic
Administrator
Hero Member
*****
Posts: 724


hostest w/ the mostest


View Profile WWW
« on: Tue, Feb 9, 2010 »

Hey guys!  I am talking with ChevyRay about maybe putting together a kind of authoritative flash games design & implementation website; something fairly library-agnostic, but AS3-centric.  I was wondering if you guys got bored over the next few days if you could start collecting some of your favorite links/posts from the forums here, as possible content we could include on this new community site.  I'll start with my recent favorite:

DogInLake's quad tree stuff

Ideally we'll pull together a bunch of posts that aren't really about how to get around specific flixel problems, but more about how to tackle interesting game design problems using actionscript.  Thanks guys!
Logged

ChevyRay
Newbie
*
Posts: 31



View Profile WWW
« Reply #1 on: Tue, Feb 9, 2010 »

I'll help start this topic off by pointing out one of my own:

Polygonal Labs: fast integer math and data structures

Polygonal is very mathy, but also a great resource for some heavy AS3 stuff. The first link alone covers lightning-fast operations in AS3 with compared results, combining/extracting color components, and some cool tricks with the ternary operator. They also have an awesome library of data structures, which is something the current Flash library has not covered very well. Useful classes for queues, stacks, trees, binary trees, linked lists, heaps, etc.

EDIT: If I remember correctly, Polygonal also did a good quadtree demonstration as well! I think it was in Java though, but Java -> AS3 is not a difficult transition for the most part.
« Last Edit: Tue, Feb 9, 2010 by ChevyRay » Logged

Adam Atomic
Administrator
Hero Member
*****
Posts: 724


hostest w/ the mostest


View Profile WWW
« Reply #2 on: Tue, Feb 9, 2010 »

o whoa i did not know bitshifting was that much faster in actionscript, i will have to scan flixel for ways to sneak that in tomorrow!!

also that's funny, i just replaced Math.abs with my own C-style toggle like that guy has, i had no idea it was actually better performing...how on earth did Adobe implement abs() to be 25x slower than that??
« Last Edit: Tue, Feb 9, 2010 by Adam Atomic » Logged

ChevyRay
Newbie
*
Posts: 31



View Profile WWW
« Reply #3 on: Tue, Feb 9, 2010 »

Yeah I try to use all my own ternary toggles for sign-checking, abs/min/max operations when it's backend heavily-used stuff that I'll never come back to. When it comes to clean code, sometimes it's not worth it for the sake of readability, but you want stuff like Flixel and FlashPunk to run with the least amount of overhead as possible, and even little stuff like this can count in the long run.

Quote
also that's funny, i just replaced Math.abs with my own C-style toggle like that guy has, i had no idea it was actually better performing...how on earth did Adobe implement abs() to be 25x slower than that??
I'm pretty sure it's just overhead from performing functions. Wrap any of that quick code into a function yourself, and it's even slower than the flash Math implementations. Go figure.
Logged

grapefrukt
Newbie
*
Posts: 1



View Profile WWW
« Reply #4 on: Tue, Feb 9, 2010 »

I'm so in!
I've never actually used flixel much, mostly because I've got my "own" way of doing flash-stuff since I've been doing it so long. But having a central place for "best-practices" and some tips on improving performance would be great.
Logged
Ronin
Newbie
*
Posts: 4


View Profile
« Reply #5 on: Tue, Feb 9, 2010 »

Great initiative!!
This is something that we all will benefit from Cheesy
Logged
lithander
Full Member
***
Posts: 169



View Profile WWW
« Reply #6 on: Tue, Feb 9, 2010 »

I like the idea of discussing as3 programming on a more generic level. Awesome initiative that I'd like to contribute to.

But... Flash performance optimizations is something I would hande _very_ carefully. I wrote a little something about my own experience with flash performance once. My advice to anyone would be to NOT implement tweaks in your engines that hear-say claims to be performant. Especially if the trick is from a 3 year old blog post like the Math.abs() one. There is no good reason why your custom implementation should be so much faster then adobes so it's not unlikely that Adobe fixed or even improved their Math functions by now!

Regarding the quad tree I'm intrigued about an advanced object managment like that. It will allow some stunning things to pull off for sure. But using it is not per-se the best approach for any project. There are many valid alternatives to implement the same thing. I think from an engine point of view what is equally important to integrating features like this is to think about how to allow the user to customize the engine to exactly fit their needs. If you offer quad trees, can the user opt out? Can he sort only some objects in and leave others out? Can he provide his own implementations and plug them in instead? If this is not carefully considered you risk to overengineer your engine. How simple flixel was to understand, modify and start out with was what I liked when I found it. The KISS principle is especially important if your language tends to be compiled to badly optimized slowly interpreted byte code like flash. In an other flash engine I've worked with I managed to get an 10% performance boost just by kicking their custom Logger/Profiler out of the base code.
« Last Edit: Tue, Feb 9, 2010 by lithander » Logged

Simplicity is the ultimate sophistication ~Leonardo Da'Vinci
ChevyRay
Newbie
*
Posts: 31



View Profile WWW
« Reply #7 on: Tue, Feb 9, 2010 »

Wow, that Polygonal post is quite ancient, I actually wasn't aware of that. These discoveries and little code bits are always followed up by tests of my own anyways, but I totally agree that you have to not be too presumptuous and take into account Adobe's current state on the issue. Even if it's a recent discovery, it's likely that they're aware of it and the near future will see updates and possible speed increases, in which case it would be much wiser to stick to the built-in methods.
« Last Edit: Tue, Feb 9, 2010 by ChevyRay » Logged

fefranca
Full Member
***
Posts: 218


10 binary lovers


View Profile WWW
« Reply #8 on: Tue, Feb 9, 2010 »

Hi Adam and Chevy,

Here is an interesting post from Senocular regarding the order of operations in AS3 for content created in the Flash IDE.

I've been using AS3 pretty much since it was created, and I never knew about the ability to use namespaces somewhat like C++ before I watched this.

I'm sure there is a lot more laying around, I do need some coffee before I can remember. The whole idea behind the website sounds great Wink
Logged

Free cake every day at #flixel on irc.freenode.net.
Use your favorite IRC client or  http://webchat.freenode.net/
zuperxtreme
Full Member
***
Posts: 116



View Profile WWW
« Reply #9 on: Tue, Feb 9, 2010 »

This might be useful for some: Ultrashock's AS tips

Bit flags sound interesting, I didn't know about them: tip 21(Bits as Flags), 22(Removing a single bitflag), 23(List all flags in a combined variable), and 24(Bitflags by bitshifting)

Kirupa's Actionscript 3 Tip of the Day

"N" (the game) tutorials: http://www.metanetsoftware.com/technique.html
« Last Edit: Tue, Feb 9, 2010 by zuperxtreme » Logged

..."without order nothing exists, without chaos nothing evolves"... 
Zoklet.net
SeiferTim
Full Member
***
Posts: 219



View Profile WWW
« Reply #10 on: Tue, Feb 9, 2010 »

Awesome! I'd like to help any way I can, although I don't know that I know that many tips and tricks lol
Logged

darthlupi
Full Member
***
Posts: 205


All Smiles


View Profile WWW
« Reply #11 on: Thu, Feb 11, 2010 »

I am pretty new to Flex and AS3, so I find this tutorial on manipulating BitmapData pretty handy:

http://www.8bitrocket.com/newsdisplay.aspx?newspage=6765

Quote
screenBD.copyPixels(charObj.displayBD,charObj.rect, charObj.point); It is pretty powerful for one line. Basically this tells the screenBD to copy all of the pixels from the charObj's displayBD instance to itself. It uses the rect as the clip area to copy and the point as the location on the screen to place the pixels it copies.

I think he did a really good job simplifying what was a pretty confusing to me in this statement.

If you guys don't mind collecting things for new Flex folks, I'll keep pushing tutorials that I have been using as I learn.

Thanks for doing this!
« Last Edit: Thu, Feb 11, 2010 by darthlupi » Logged

To take care of that not so fresh feeling: #flixel on irc.freenode.net.

Use your favorite IRC client or  http://webchat.freenode.net/
Adam Atomic
Administrator
Hero Member
*****
Posts: 724


hostest w/ the mostest


View Profile WWW
« Reply #12 on: Fri, Feb 12, 2010 »

stuff like that is perfect!
Logged

bjc
Newbie
*
Posts: 19



View Profile
« Reply #13 on: Fri, Feb 12, 2010 »

I love Nicolas Cannasse's blog http://ncannasse.fr/. It is sometimes referenced in by Michael Baczynski's Polygonal Site http://lab.polygonal.de/ (as Nicolas is the developer of Haxe and Michael's more recent developments evolve around said technology).

But his site has some awesome information about small sometimes flash bytecode specific optimisations, as well as a couple of nice math tricks such as the fast inverse square root trick (http://ncannasse.fr/blog/fast_inverse_square_root) as implemented in his physics engine http://code.google.com/p/physaxe/.

Another nice "optimization" oriented blog is that of Joa Ebert which can be found at the appropriately named:  http://blog.joa-ebert.com/.

(btw Adam, I love what you have done to the Flixel website, particularly your promotion of FlashPunk. It speaks highly of the character or "feel" behind the project(s) and it's community.)
Logged
bjc
Newbie
*
Posts: 19



View Profile
« Reply #14 on: Sat, Feb 13, 2010 »

fefranca, that namespace video is amazing! I almost ignored it since i thought you were simply talking about "packaging scope" namespaces. But using a namespace as a compile time state manager is awesome! reminds me of #DEFINE in c/c++. Why haven' I seen this used before!

I can already see that i will start using this for some 'release' & 'debug' drawing functions as well something like collision impl. ('flixel' collision functions vs 'box2d' collision functions).

... I better get back to watching the video... I think there is more to it that this...

Oh and before I forget: I know it's not really made for actionscript (honestly I've never really used bit shifting in as) but I imagine some of these optimisations might work on int and uint types. http://graphics.stanford.edu/~seander/bithacks.html
« Last Edit: Sat, Feb 13, 2010 by bjc » Logged
Pages: [1] 2
  Print  
 
Jump to: