Atom Swing 1

Sticky Elemental Snow


In this piece I'm working out a way to randomly select one of the four corners of a square, and rotate it around that pivot point.

Imagine a sign, tacked to a fence at four corners. What if all but one tack came loose. The sign would then swing down from that pivot corner. In real life, the sign would swing back and forth until it ran out of momentum. In this piece, however, I'm keeping this model really simple and just rotating the square (on a pivot point) until it hangs straight down. Once the corner diagonal to the pivot corner is pointing down, the square is ready to drop.

The Cell class in this piece assigns a random corner (to be the pivot point) and then draws and positions the graphics based on the corner's offset, before passing it through targetParent.addChild(thisCell). Rotation direction is also based on this corner position. This is all to get around the current problem of not being able to reset the registration point of a movie clip at run time.

To fake changing the registration point at run-time, I went with the "offset" within a container approach. So, a container sprite is created first (which is also used for positioning the square in the grid). An inner sprite is nested within it. This will hold the graphics for the cell's square. One of four corners of the square is set as the pivot corner. The graphics of the inner sprite are then offset and positioned, according to which corner is the fake registration point.

The red dot helps me quickly visualize which corner is the pivot point.

Why bother with all this? Because the rotation property is relative to the registration point. If we position the inner sprite correctly, when we animate the container sprite's rotation it looks as though it's rotating around our fake registration point.


A link to download source files is near the bottom of this page.


-- click on the cells, to activate them --


--> Download Source Files <--