r3dux.org

A number-pimping side project from the valleys in *NEW* upside-down flavour.

  • Home
  • ABOUT
  • OLD SITE
  • SEARCH
  • FEEDBACK

ActionScript 3.0: Per-Pixel Collision Detection inna rub-a-dub Peggle Stylee

r3dux | January 22, 2010

I’ve been working on writing a collision detection class, and it’s not as easy as you might think. It’s simple enough to boundary test (i.e. bounding-box overlap test), but to do per-pixel collisions you have to dump your symbol data into a BitmapData object, and you HAVE to use the top-left as the registration point for all your colliding symbol instances, which means you end up doing a lot of offsets & shiz… Ho hum.

Anyways, I knocked this Peggle / Pachinko thing together over the course of yesterday and today. You can place as many “pegs” as you want, wherever you want ‘em, same with the “balls”, and in theory, I should be able to scale both pegs and balls to any size while still keeping the collisions accurate, but I’ve not tested that yet because after debugging this for a while I need a break.

But hey, look at the purty colours :)

No source-code for this one just yet as it’s not in a fit state (it has waaaay too much debug output per collision that I don’t want to strip out just yet, and enough swearing to make a salty sea-dog blush ;) ). When I’ve knocked it into shape some more I’ll chuck the Peg, Ball and Collision classes here in an update.

Update: Source code and flash files now available after the jump. Some of the code is a bit yucky, so apologies in advance for my bodge-hackery =P

Read the rest of this entry »

Comments
4 Comments »
Categories
Coding
Tags
ActionScript, Adobe, BitmapData, Boundary, Collision, CS4, Detection, Flash, Pachinko, Peggle, Per-Pixel
Comments rss Comments rss
Trackback Trackback

Edward Sharpe and the Magnetic Zeros – Home

r3dux | January 21, 2010

YouTube Preview Image

Alabama, Arkansaaaaaaww, I do love my Ma & Pa, but not as much as I do love you…

Lovely tune, and it’s got some pretty corky lyrics if you wanted to sing along…

Taken from the debut album: Up From Below.

Comments
No Comments »
Categories
Music
Tags
Edward Sharpe, Home, Magnetic Zeros, Video
Comments rss Comments rss
Trackback Trackback

ActionScript 3.0: A Dynamic Frame Rate Switching Class to Lower CPU Usage

r3dux | January 20, 2010

Flash gets a lot of negative press because it’s seen as using a heap of CPU time and bogging everything down. And it’s a fair cop. Most flash will eat up your CPU cycles even when it’s sitting there doing nothing. But this isn’t a fault of flash, but rather of flash developers. Let me explain…

When you start a piece of flash work, you assign it a frame rate at which you want it to run, so it’ll update the screen, say, 30 times a second. This is all fine and good for when you’re animating things on the stage. But what about when you’re not? Well, it’s still running at 30 frames per second and chewing up your CPU like a crazy melon farmer. This is Not A Good Thing. So, anyhow, I’m watching this video about SWF Framerate Optimisation, and the guy’s showing how you can modify your code to lower the frame rate when there’s not a lot happening, and bring it back up when you’re animating. So I had a crack at it, and lo & behold, it works fine for the specific piece of flash I’d coded it into, so I wondered if I couldn’t just go and make a RateController class. This way, I could add a RateController object to any project to dynamically change the project’s frame rate depending on whether the mouse was over the stage or not.

And after much swearing about not having global access to the stage properties, I found that I COULD!!!

Here’s a working example placed into the attracting particles code I wrote yesterday:

Note: The animation starts at full speed for two seconds on startup. It’ll drop to the sleeping rate (5 fps) two seconds after the mouse leaves the stage, and then ramps back up to its waking rate (30 fps) instantly when the cursor is back over the stage. The FPSCounter shows intermediate numbers because it’s based on an average.

To add a RateController to any flash project, you can just use something like:

import RateController;
 
// Add a new RateController, uses the root stage, runs at 5fps when sleeping, 30fps 
// when active (i.e. when mouse is over the stage), and uses a 2000 millisecond
// delay after the mouse leaves the stage before dropping the FPS to the sleeping rate.
addChild(new RateController(stage, 5, 30, 2000));

Not bad, eh?

Full class code & file downloads after the jump…

Read the rest of this entry »

Comments
3 Comments »
Categories
Coding
Tags
ActionScript, ActionScript 3.0, Adobe, Class, CPU, CS4, Dynamic, Flash, Frame, Framerate, Rate
Comments rss Comments rss
Trackback Trackback

ActionScript 3.0 Particle Systems #6: Particle Attraction

r3dux | January 19, 2010

More ActionScript… This time we’re attracting the particles towards the mouse cursor when the distance between them is low enough… Looks alright, just a kinda fun effect & dead simple to code.

Source code and flash files on the flipside…

Read the rest of this entry »

Comments
No Comments »
Categories
Coding
Tags
ActionScript, ActionScript 3.0, Adobe, Attraction, CS4, Effect, Flash, Motion, Particle, Systems
Comments rss Comments rss
Trackback Trackback

Flobots – Handlebars

r3dux | January 18, 2010

YouTube Preview Image

Your path is your own to choose. So choose wisely.

Love it.

Comments
No Comments »
Categories
Music
Tags
Choice, Flobots, Handlebars, Video
Comments rss Comments rss
Trackback Trackback

« Previous Entries Next Entries »

Translate

Categories

Archives

Tags

3D ActionScript ActionScript 3.0 Adobe AI Ballarat Bash C++ Class Convert CS4 Effect Error Film Flash GLSL Gnome Hack How-To install Jaunty Java Kinect Linkage Linux Mash-Up Microsoft Motion OpenGL Particle Problem PS3 Remix Retro script Slides Sound Systems Texture Ubuntu Video VirtualBox Wii Windows XBox

Gamercard

OpenR3dux

Misc.

Flattr this

RSS Feed

r3dux twitter feed



“The biggest difference between time and space is that you can't reuse time.”

 - Merrick Furst

rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox