PDA

View Full Version : Dyanimcally draw an expanding box


Cyanide
05-27-2003, 09:07 PM
I would like a tutorial on how to programatically draw an expanding box using an origin point (where the box starts expanding from), a point for the top left corner of the box, and a point for the bottom right corner of the box. Preferably all of that would be done using a single function that could be called multiple times similtaneously (so you can draw more than one box at a time).

I tried doing this myself but I could only get it to expand from the top left corner to the bottome right corner correctly. I think the best way to do this would be to have 4 small movieClips. Have the function place them at the origin point, assign each clip to a corner of the box, calculate the slope of the line from the origin to that point and then move the clip along that line to the corner while drawing lines between the clips. The problem is that I don't know how to do that.

doublethink
06-12-2003, 08:23 AM
you could try posting that in the challenges section of these forums.

webguy
07-08-2003, 10:25 PM
using the drawing API it appears that the registration point is 0,0. So just center 0,0 in your box and it will expand as you want.


function makeBox () {
newBox = _root.createEmptyMovieClip("newClip"+levelCount, levelCount++);
newBox.lineStyle(1);
newBox.moveTo(5,5);
newBox.lineTo(-5,5);
newBox.lineTo(-5,-5);
newBox.lineTo(5,-5);
newBox.lineTo(5,5);
newBox._x = Stage.width/2;
newBox._y = Stage.height/2;
newBox.onEnterFrame = function () {
this._xscale+=10;
this._yscale+=10;
}
}

_root.onMouseDown = function () {
makeBox();
}


Click in the window to test it.