[英]away3d and starling resizing issue
我在嘗試在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;
}
它適用於Starling實例,但不適用於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;
我要實現的是在將Size設置為“百分比”時將縮放比例設置為"NO_BORDER"
,將align設置為"Top Center"
並具有最小的高度和寬度時在傳統Flash中所實現的效果。
如何實現呢?
謝謝
馬捷
好吧,我發現調整大小的方法是更新視圖。 您可以將居中或重新放置,或者將flash.display.Sprite
容器定位在添加了Away場景的位置,也可以自行查看。
想法很棘手,因為您必須找出該視圖的scaleX
和scaleY
的方法是“ DEAD END ”,這意味着它們是空的方法,永遠不會發生任何變化。 因此,您確實必須 &只能更改width
& height
屬性。
這里列出了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;
}
我認為您不能通過簡單地在stage3DProxy上設置width / height屬性來調整away3d實例的大小。 我通過在view3D上設置寬度/高度來實現這一點:
view = new View3D();
//...later
private function stageResizeHandler(evt:Event):void
{
view.width = stage.stageWidth;
view.height = stage.stageHeight;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.