我应该在哪里使用if else语句放置我的函数stage.fullScreenSourceRect?

时间:2013-12-04 16:05:49

标签: android actionscript-3 flash

我应该在哪里使用if else语句放置我的函数stage.fullScreenSourceRect?

我试图计算设备显示比率&根据设备比例定位动画片段。即如果显示比例为16:9,则800 x 450将位于中心位置。

代码中没有错误。但如果不起作用。

    stage.displayState = StageDisplayState.FULL_SCREEN;
    stage.align = StageAlign.TOP_LEFT;
    stage.scaleMode = StageScaleMode.NO_SCALE;
    //stage.fullScreenSourceRect = new Rectangle(0,0,800,600);
    //stage.fullScreenSourceRect = new Rectangle(0,0,800,535);
    //stage.fullScreenSourceRect = new Rectangle(0,0,800,450);

//calcualting device display ratio & positioning the movieclip as per device ratio.
//i.e if display ratio is 16:9 800 x 450 will positioned n centre.

var scrnratinum:Number;
scrnratinum=(stage.stageWidth/stage.stageHeight);
//for 4:3 i.e 1.3
if (scrnratinum<=1.20 && scrnratinum>=1.39)
{
    stage.fullScreenSourceRect = new Rectangle(0,0,800,600);
}
//for 3:2 i.e 1.5
if (scrnratinum<=1.40 && scrnratinum>=1.49)
{
    stage.fullScreenSourceRect = new Rectangle(0,0,800,535);
}
//for 16:9 i.e 1.8
if (scrnratinum<=1.60 && scrnratinum>=1.79)
{
    stage.fullScreenSourceRect = new Rectangle(0,0,800,450);
}


var scrnratio:TextField = new TextField();
scrnratio.text = "Screen Ratio  " + scrnratinum.toFixed(2);
scrnratio.width = 400;
scrnratio.height = 600;
scrnratio.x = 300;
scrnratio.y = 300;
addChild(scrnratio);

//this is the movieclip being loaded. its actual w x h is 800 x 600.
var bringclip = new emptyclip();
addChild(bringclip);
bringclip.x= ((stage.stageWidth)/(2));
bringclip.y= ((stage.stageHeight)/(2));

1 个答案:

答案 0 :(得分:0)

我相信你设置错误的情况。你想这么做吗?

if (scrnratinum>=1.20 && scrnratinum<=1.39)
{
    stage.fullScreenSourceRect = new Rectangle(0,0,800,600);
}
//for 3:2 i.e 1.5
if (scrnratinum>=1.40 && scrnratinum<=1.49)
{
    stage.fullScreenSourceRect = new Rectangle(0,0,800,535);
}
//for 16:9 i.e 1.8
if (scrnratinum>=1.60 && scrnratinum<=1.79)
{
    stage.fullScreenSourceRect = new Rectangle(0,0,800,450);
}