Action Script in Action Welcome, Guest. Please login or register.
Always stay logged in

Login with username, password and session length
Home Help Search Login Register
Pages: [1]
  Print  
Author Topic: Registration Point Question  (Read 827 times)
Wayne
Administrator
Full Member
*****

Karma: 0
Offline Offline

Posts: 119


BEER ,beeeeeeeeeeer ah beer.


« on: March 26, 2009, 05:50:33 AM »

As I have seen and been ask around several forums, this one question keeps coming up. " Can I change the registration point of a object with scripting." The answer is Yes & No. Got you confused? Well you can not physically in run time change it, but you can lie to you viewer/flash player to think it is some where its not.

 

Now I will take you away from the wall and put you out of pain.
The code is small and uses a function to achieve this.
This is the function: 
Code:
function origin()
    {
        var bounds = this.getBounds(this._parent);
        return ({x: (bounds.xMin + bounds.xMax) / 2, y: (bounds.yMin + bounds.yMax) / 2});
    }
Now what we will do is for this example we will rotate an object so you will see the function at work.

This is setting up your rotation: 
Code:
onClipEvent (load)
{   
     this.rotation_speed = 2;
    this.rotation_origin = origin();
}

Now we need to create a loop to keep this running: 
Code:
onClipEvent (enterFrame)
{
    this._rotation = this._rotation + rotation_speed;
    var curr_origin = origin();
    this._x = this._x + (this.rotation_origin.x - curr_origin.x);
    this._y = this._y + (this.rotation_origin.y - curr_origin.y);
}

All this code is set inside a sprite so now draw a box and name it box.
Convert it to a sprite.
Now go to Transform and set your registration point to custom and enter X: -69.65  Y: -78.8.
Now test. If you did everthing right it will rotate as if your Res.Point was set to center.

Hope this helps.

Wayne
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC
DG Style by Fth*