Away3D/Starling stage resize problem

Software: Away3D 4.x

digitaloranges, Newbie
Posted: 21 January 2013 11:59 AM   Total Posts: 4

Hello all,

I’m working a project that uses Away3D with a 2D Starling layer rendered on top of it and it all works perfectly apart from a strange problem I’m having when the stage is resized.

When Event.RESIZE is triggered, I use Starlings RectangleUtil.fit to find the best fit rect for the stage size.  I then set the stage3DProxy position and width to this rectangle and also set Starlings viewport to these coordinates too. I also change the width of the current Away3D view.

protected function onStageResize(e:Event):void
{
  
// get best fit rect for set stage size and new stage size
  
var bestRect:Rectangle RectangleUtil.fit(new Rectangle(00,   BBDisplaySettings.stageWidthBBDisplaySettings.stageHeight), new Rectangle(00stage.stageWidthstage.stageHeight), ScaleMode.SHOW_ALL);

   
// resize Away3D viewport
 
if (_away3DView)
            
{
               
// this code sets the correct 3D View size, but the 3D coordinates     //are incorrect.  If these 2 lines are commented out, the 2d coordinates are //correct but the 3d view doesn't resize
               
_away3DView.width bestRect.width;
               
_away3DView.height bestRect.height;
     
}

            
// adjust stage3d proxy size
            
if (_starling)
            
{
                _stage3DProxy
.width bestRect.width;
                
_stage3DProxy.height bestRect.height;
                
_stage3DProxy.bestRect.x;
                
_stage3DProxy.bestRect.y;
  
_starling.viewPort bestRect;
            
}

        } 

On first impression, this seems to work but when I try to project a 3D coordinate to 2D, the position is incorrect.  However, if I don’t adjust the view3D size, the position IS correct BUT the view3D instance doesn’t scale to fit the screen and stays the same size in the top left corner.

Can anyone shed any light on this?

   

m_pedro, Newbie
Posted: 27 January 2013 11:01 PM   Total Posts: 7   [ # 1 ]

From what I have experienced, stageWidth and stageHeight are only properly calculated after the Resize event has been triggered, otherwise it uses the default width and height which is 500 by 375 I believe.

If you initialize starling and away3D after the Resize event, you shouldn’t have to manually scale the viewport. I believe it is taken care of for you since Resize will change the stageWidth and stageHeight to match your current device or screen size. It works for me.

   

digitaloranges, Newbie
Posted: 30 January 2013 09:38 AM   Total Posts: 4   [ # 2 ]

Thing is, I want to dynamically scale the whole view whenever the user resizes the window and I’m not sure your solution would work for that.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X