Blog

Posts tagged with “play”

Recreating Grant Skinner's sphereTest Part 2 — almost figuring it out the hard way.

Working off the tests I did previously to try and recreate Grant Skinner's original sphereTest, I drew a bunch of discs, moved them out along the Z-axis randomly between min and max values, and distributed them randomly along the X and Y axes using the rotationX and rotationY attributes. Then I incremented each disc's rotationY value with the onEnterFrame event.

Obviously, the stack order would be need to be worked on, but not a bad start. To get the stack order, I needed to find the relative position of each disc along the Z-axis. To do this, I used the Z position as a circle's radius, and derived approximately how many pixels of movement each degree of rotation along the X axis represented. Once I found that new value, I'd do the calculations again for the Y rotation. To cut down on per-frame math, I figured out the z-position relative to X rotation immediately, and stored it since it wouldn't change. I only did the position relative to Y when needed. Also, I only approximated the Z position by dividing the diameter values by 180 (or, multiplying by 0.005555555556, which is faster and results in the same value), instead of mucking about with the position along the arc. It wasn't exact, but it was a good enough value to sort on. once I had the relative position, Discs that were relatively "closer" to the viewer were then sorted to appear in front of ones that weren't. This involved iterating through the discs to change their Y rotation, sorting the disc array on their derived relative value, and re-iterating to do the stacking. Not great, performance-wise, and still a little jumpy at the poles, but it worked.

To make the stacking appear smoother I ensured that "closer" discs that had an initial maximum Z position were always stacked in front, of other discs, then worked back until the "farther" maximum Z discs were sorted to the back.  Next, I made the entire sphere "follow" the mouse. I did this by calculating the angle of the line from the mouse's position and the center of the sphere relative to the x-axis (non-trivial math, to be honest -- at least for me) and rotating the entire sphere around its Z-axis to make the disc's Y rotation move towards the mouse.

This looked fairly good to me. Then I went back to Grant's sphereTest and noticed that his sphere wasn't roting along the Z-axis. Each individual disc simply moved towards the mouse regardless of it's position relative to the Y-axis "pole". It was as if the sphere's Y-axis was moving independently of the discs. Actually, it looked as if they were moving around fixed X and Y axes simultaneously. But using each disc's rotationX and rotationY attributes meant the discs' X-axes were all over the map. My initial thought on how to emulate this behaviour was, oddly enough, quite complex. I thought that I would need rotate the sphere towards the mouse around its Z-axis; then correct that Z-rotation by moving the discs in the opposite direction around their own z-axis; then spin the entire sphere around it's own y-axis. Once that was done I'd need to calculate the relative Z of each disc based not only on their internal rotations, but on also on the sphere's rotations as well.

In short, a metric shit-load of math.

For each disc.

For every frame.

Not good.

Then I found the 3DMatrix object in Adobe's Flash CS4 documentation; Swore out loud; and threw out most of my work to this point. I'll let you know what I replaced it with in my next blog post.

Tags: , ,
2009.12.14 12:00 PM | Permalink 0 Comments

Recreating Grant Skinner's sphereTest Part 1 — how 3D rotation in Flash treats each axis differently

A few months back, Flash guru Grant Skinner tweeted about a "little" sphereTest he had been working on while playing with the new 3D rotation api in Flash Player 10. He has since added several variations to it, but I thought it would be a fun exercise to try an re-create the original demo, for my own edification. Here is the first part of my journey.

So I initially just created a bunch of discs at equidistant points from the center; randomly rotated them along the X and Y axes; and started incrementing those rotation values over time. Weird stuff happened. things moved in bizarre directions. I did the same with the X and Z axes. More weird stuff. Y and Z. Even more. I tried putting the discs on different axes. Still more weirdness.  Obviously I needed to understand how 3D rotation worked. So I built the following test harness to better understand the interactions between each axis.

The interface is a little clunky (it IS a test harness, after all) but essentially it works thusly: given three different sets of discs — initially positioned out on either the X, Y, or Z axis — you can randomly rotate these discs along one or more axis, and then increment the rotation value along one of those axes. Randomizing or reseting initial rotation positions will stop and recenter each sphere.

After playing with this for a while, I realized what was happening. The X axis is the runt of the litter. Rotating an object along the X axis has no affect on the position of the other axes, but rotating the along the Y and Z axis also rotates the relative position of the X axis in space. Also, rotation along the Y axis doesn't affect the position of the Z axis, but the Y axis is rotated with changes to the Z Axis rotation.

All that to say, if I was to recreate Grant's sphereTest, I would most likely need to initially position the discs along the Z axis, randomize around the X and Y axes, and incremently rotate along the Y and Z. But how, exactly t do that wasn't exactly easy. More on that in the next posts.

Tags: , ,
2009.12.09 11:11 AM | Permalink 0 Comments

Blitz Brick - My first flash game.

I made this as the final assignment for Flash Authoring - MTM1527 as part of Algonquin's Interactive Multimedia Graduate Certificate.

The levels are loaded from an external XML file. My hope was to unlock a level editor when you finished the game,

Tags: , ,
2009.11.13 08:25 AM | Permalink 0 Comments

KaBlam

A proof-of concept replacement for the right-click in flash games.
This is a simple minesweeper-a-like game I threw together to test this solution to not being able to use right click in Flash. I'm not sure if anyone else has Apparently other people have tried similar solutions, but I haven't seen any (ahem … in a Flash game, at least — see bellow).

I've purposely left out how to play instructions on this, to see if users can figure out the mechanism on their own.

Once you've had enough, please feel free to Fill out this brief survey Just letting me know what you thought.
EDIT:
Turns out I re-invented the Pie Menu, though mine works a little differently than the standard model. In mine, the center click has it's own action, and use keyboard short cuts for auto-menu selection¹. That's what you get for only playing retro games, I guess.

¹play with the arrow keys

Tags: ,
2009.07.08 08:15 AM | Permalink 0 Comments
← Previous Page 2 of 2