PDA

View Full Version : localToGlobal() and its evil cousin



nih
March 4th, 2005, 10:45 PM
I have the following objects:


_root.map.transformations.maptiles.spawner
_root.pawns.spawnedobject

The spawner object is having the heck transformed out of it, and the spawned object needs to follow it. I simply haven't managed to get a handle on localToGlobal() or its friend globalToLocal(). Documentation and tutorials haven't made things clearer, as neither of these work as I expect them to.

What I've found is that if I do localToGlobal inside the spawner in the form of:

this.localToGlobal()
...I can use the resulting coordinates to place the spawned object correctly. I expected to need to use:

_root.pawns.globalToLocal()
...on those results to get the final location, but using it actually misplaced the spawned object. So I didn't use this function at all.

Now an object in a third path is breaking. The path is:

_root.map.transformations.tileanimation.newspawned object

I can see where I'm going wrong, but I can't see what I should be doing to get this working correctly. Any advice/examples?

nih
March 4th, 2005, 11:03 PM
Time to answer my own question! :) I finally found this on the macromedia site, of all places. Someone check hell for temperature drops.




// Remember: The _x and _y properties of a movie clip represent the
// 0,0 coordinate of the movie clip, in terms of the _parent timeline.

// To get the _x and _y coordinates of a movie-clip, in terms of
// the global coordinate system, the point you're looking to convert
// is in fact the 0,0 coordinate of the movie clip.

// I was getting hung up trying to pass the _x and _y properties
// of the movie clip for coordinate conversion.

// Where: target_mc is a reference to some movie-clip,
// anywhere in a flash project.

var point: Object = {x:0,y:0};
target_mc.localToGlobal(point);

globalXCoord = point.x;
globalYCoord = point.y;



I was making the exact same mistake this guy was. And I was also trying to pass the rotation and somehow expecting it to work. Probably through magic.

nih
March 4th, 2005, 11:04 PM
And here's what I ended up doing, just so everyone has a real example:


var point:Object = {x: 0, y: 0};
this.localToGlobal(point);
_root.World.Ground.Ground_Rotation.Ground_Position .globalToLocal(point);