【问题标题】:away3d and starling resizing issueaway3d 和八哥调整大小问题
【发布时间】:2013-03-01 16:19:39
【问题描述】:

我在尝试在 stage3d 中正确调整 away3d Gold 和 Starling 的大小时遇到​​问题,两者都在一个游戏中工作。

我有 4 个starling 实例和 1 个由 stage3dProxys 处理的 Away3d 实例。

这一切都适用于初始大小。在浏览器中调整游戏大小时会出现问题。

游戏 .swf 最终会被另一个父级 .swf 加载,但是当游戏直接加载到它自己的 HTML 模板上时,也会发生同样的事情。

我现在拥有的是:

  

stage.addEventListener( Event.RESIZE, onResize, false, 0, true );

    private function onResize(event:Event):void {
            _stage3DProxy.width = stage.stageWidth;
            _stage3DProxy.height = stage.stageHeight;
    
    
        }

它适用于八哥实例,但不适用于远距离 3d 实例。 并且它没有显示应该在舞台之外的剪切图像。

我也试过不成功:

  

starling.stage.stageWidth = this.stage.stageWidth;
             starling.stage.stageHeight = this.stage.stageHeight;

             var viewPort:Rectangle = RectangleUtil.fit(
                new Rectangle(0, 0, stage.stageWidth, stage.stageHeight),
                new Rectangle(0, 0, stage.fullScreenWidth, stage.fullScreenHeight),
            ScaleMode.NO_BORDER);

         Starling.current.viewPort = viewPort;

我想要实现的是您在传统 Flash 中将“大小”设置为“百分比”,将比例设置为:"NO_BORDER",对齐为:"Top Center",并具有最小高度和宽度。

如何做到这一点?

谢谢

伙伴

【问题讨论】:

    标签: actionscript-3 stage3d away3d starling-framework robotlegs


    【解决方案1】:

    Away3D

    好吧,我发现重新调整大小的方法是更新视图。您可以居中或重新定位添加 Away 场景的 flash.display.Sprite 容器或视图本身。

    这是一个棘手的想法,因为您必须发现 scaleXscaleY 的视图方法是'DEAD END',这意味着它们是空的方法,不会改变什么所以曾经。所以你真的必须并且只能更改 widthheight 属性。

    这里列出了View3D 的所有DEAD END 方法,就像它们出现在源代码中一样:

    // dead ends:
        override public function set z(value : Number) : void {}
        override public function set scaleZ(value : Number) : void {}
        override public function set rotation(value : Number) : void {}
        override public function set rotationX(value : Number) : void {}
        override public function set rotationY(value : Number) : void {}
        override public function set rotationZ(value : Number) : void {}
        override public function set transform(value : Transform) : void {}
        override public function set scaleX(value : Number) : void {}
        override public function set scaleY(value : Number) : void {}
    

    八哥

    经过团队的实验,我们项目中的工作如下:

    目标:重新调整背景的大小,就像将大小设置为 percentage 时一样,将比例设置为:NO_BORDER,对齐为:Top Center

    //Necessary variables
    public var backgroundContainerStage:Starling;
    public var anyOtherContainerStage:Starling;
    public var stage3dProxy:Stage3DProxy;
    public var scaleRatio:Number;
    public var originalHeight:Number = 900;
    
    // ... {HACK} ... {HACK}
    // Add your Listeners in the constructor for Event.AddedToStage 
    // and set the handler to init... Or any other method you prefer to add the 
    // listener on the `Event.RESIZE`. 
    //
    // Also populate the stage3DProxy how ever you wish. 
    // We did it this way: 
    //_stage3DProxy = Stage3DManager.getInstance(stage).getFreeStage3DProxy();
    //
    // ... {HACK} ... {HACK}
    
    public function init(event:Event=null):void{
      stage.addEventListener( Event.RESIZE, onResize, false, 0, true );
    }
    
    // The IMPORTANT PART !!!!!!!!
    public function onResize():void  {
      scaleRatio = stage.stageHeight/originalHeight;
      backgroundContainerStage.stage.stageWidth =
          anyOtherContainerStage.stage.stageWidth =
              stage3dProxy.width = stage.stageWidth;
    
      // Need to get the Starling Sprite cause the the Starling instances don't allow to
      // set values for their `x` and `y` properties.
      var background: Sprite = backgroundContainerStage.getChildByName('background') as Sprite;
      var uiContainer: Sprite = anyOtherContainerStage.getChildByName('uiContainer') as Sprite;
      //First, RE-SIZE
      background.scaleX = background.scaleY =
         uiContainer.scaleX = uiContainer.scaleY = scaleRatio;
    
      //Then, RE-POSITION top-Center
      background.x =
         uiContainer.x = stage.stageWidth - background.width >>1;
    
    }
    

    【讨论】:

      【解决方案2】:

      我认为您不能通过简单地在 stage3DProxy 上设置宽度/高度属性来调整 away3d 实例的大小。我通过在 view3D 上设置宽度/高度来实现这一点:

          view = new View3D();
      
          //...later
      
          private function stageResizeHandler(evt:Event):void
          {
              view.width = stage.stageWidth;
              view.height = stage.stageHeight;
          }
      

      【讨论】:

      • 谢谢,这有点帮助
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-18
      • 2013-06-13
      • 2010-10-03
      • 2010-11-29
      • 1970-01-01
      • 2021-09-20
      • 2011-07-05
      相关资源
      最近更新 更多