如何用Actionscript改变Flash舞台的坐标原点?

发布于 2024-08-18 06:49:11 字数 219 浏览 1 评论 0原文

我想我以前这样做过,但找不到代码。

Flash 与许多其他图形框架一样使用左上角作为坐标原点 (0,0),因为这是底层内存模型的惯例。

但如果原点位于舞台中心,对于我的计算来说会更简单,因为所有游戏都围绕中心旋转并使用大量三角学、角度等。

是否有一些内置方法,例如 Stage::setOrigin( uint, uint ); 或者类似的东西?

I think I did this before but can't find the code.

Flash as many other graphical frameworks use the top-left corner as the coordinate origin (0,0) because it's how the underlying memory model is by convention.

But it would be really simpler for my calculations if the origin was in the center of the stage, because all the game revolves around the center and uses a lot of trigonometry, angles, etc.

Is there some built-in method like Stage::setOrigin( uint, uint ); or something like that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

゛清羽墨安 2024-08-25 06:49:11

创建一个重写 x 和 y setter 和 getter 的类来处理计算。舞台上的任何 MovieClip 都应该扩展这个新类。

package {
    // imports

    public class MyDisplayObject extends DisplayObject
    {

        private var originX:Number = 0;
        private var originY:Number = 0;

        public function MyDisplayObject() {
            // constructor stuff
            originX = stage.stageWidth / 2;
            originY = stage.stageHeight / 2;
        }

        override public function set x($x:Number):Void {
            super.x = originX + $x; // use super to avoid these setters and getters
        }

        override public function set y($y:Number):Void {
            super.y = originY + $y;
        }

        override public function get x():Number {
            return super.x - originX;
        }

        override public function get y():Number {
            return super.y - originY;
        }
    }
}

奖励:您可以随时更改原点值,因此它不必位于舞台的中心。

Create a class that overrides the x and y setters and getters to handle the calculations. Any MovieClips on stage should extends this new class.

package {
    // imports

    public class MyDisplayObject extends DisplayObject
    {

        private var originX:Number = 0;
        private var originY:Number = 0;

        public function MyDisplayObject() {
            // constructor stuff
            originX = stage.stageWidth / 2;
            originY = stage.stageHeight / 2;
        }

        override public function set x($x:Number):Void {
            super.x = originX + $x; // use super to avoid these setters and getters
        }

        override public function set y($y:Number):Void {
            super.y = originY + $y;
        }

        override public function get x():Number {
            return super.x - originX;
        }

        override public function get y():Number {
            return super.y - originY;
        }
    }
}

Bonus: you can change the origin values whenever you want, so it doesn't have to be at the center of the stage.

我的奇迹 2024-08-25 06:49:11

创建一个 MovieClip 或 Sprite,并将其作为根对象添加到舞台(而不是添加到舞台),位置为 stage.width/2、stage.height/2。然后当您将游戏对象添加到其中时。将游戏对象添加到该剪辑内的 0,0 处,它们将位于舞台中央。

Create a MovieClip or Sprite and add that to the stage as your root object (instead of adding to the Stage) at stage.width/2, stage.height/2. Then when you add your game objects to that instead. Add your game objects at 0,0 inside of that clip and they will be centered on the stage.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文