Rotate a displayObject and set its new rotation as "default"?

This is, probably, a really newbie question, I don’t know if it is the right place to ask, but, well, is it possible to rotate a movieclip and reset its rotation point while maintaining the rotated state? :sweat_smile:

For example, if I do this on a mC:

testObject.rotation = 90;

Can I keep the object rotated and just reset its rotation to 0?

Thanks! :sweat_drops:

You could have the movieclip rotated 90 degrees inside a sprite and then do any other rotations on the sprite.

1 Like

Thanks! :smile: But for what I’m thinking I’d have to override its rotation because it may have a child object rotating inside already. :sweat_smile:

The way I would approach it is using another variable to save the last “pinned” rotation, and a setter for “new rotation” that will take into account the pinned rotation when calculating.

mc.rotation = 90;
var pinned = mc.rotation;

var newRotation (get, set):Float

function set_newRotation(value)
{
   mc.rotation = pinned + value;
}

But I wonder if there is a “trick” in the haxe language itself to achieve this, because I’m also new to the language…

The thing to do is to always have the parent/child arrangement.

class CustomRotationObject extends Sprite {
    private var child:DisplayObject;
    
    public function new(child:DisplayObject) {
        super();
        
        addChild(child);
    }
    
    public function setDefaultRotation():Void {
        child.rotation += rotation;
        rotation = 0;
    }
}

Usage:

var rotatedTestObject = new CustomRotationObject(testObject);
addChild(rotatedTestObject);

rotatedTestObject.rotation = 90;
rotatedTestObject.setDefaultRotation();

This will cause the child to appear at 90° when the parent is at 0°.

1 Like

Sorry for diverting the subject a little bit, but I’m now exploring the language, and I was wondering if this could help (instead of overriding), or maybe I misunderstand it?

1 Like

That would allow you to add the setDefaultRotation method yes,
but it wouldn’t allow to customize the constructor.
(which btw isn’t missing a this.child = child?)

1 Like

Thanks for the infos and answers, @itzikiap, @player_03, @ibilon and @bubba_169.

Guess I’ll have to stick with the parent-child relationship and re-think the way I’m building things here, or maybe simplify my idea, since it looks like it isn’t possible to rotate + override the rotation property… :sweat_smile:

Oops, you’re right!

Static extensions (and, for that matter, abstracts) can’t store extra data. All they do is manipulate the data that’s already there.

1 Like