组件的方向不起作用

时间:2013-05-18 09:07:13

标签: actionscript-3 orientation starling-framework

我编写这段代码,为了测试方向变化,我绘制了一个宽度= stage.stageHeight的四边形,以及height = stage.stageHeight,当改变方向时,四边形的宽度显示为800而不是[阶段。 stageHeight = 1232,stage.stageWidth = 800] mobileTest.as

package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageOrientation;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.StageOrientationEvent;

import starling.core.Starling;
import starling.display.Quad;

public class mobileTest extends Sprite
{
    private var myStarling:Starling;
    public function mobileTest()
    {
        super();
        stage.align = StageAlign.TOP_LEFT;
        stage.scaleMode = StageScaleMode.NO_SCALE;
        stage.addEventListener(flash.events.Event.RESIZE,onResize);
    }

    private function onResize(e:flash.events.Event):void
    {

        if (myStarling == null)
        {
            Starling.handleLostContext = true;
            myStarling = new Starling(Main,stage);
            myStarling.start();
        }
    }
}
}

Main.as class

package
{
import feathers.themes.AeonDesktopTheme;

import starling.core.Starling;
import starling.display.Quad;
import starling.display.Sprite;
import starling.events.Event;

public class Main extends Sprite
{
    private var theme:AeonDesktopTheme;
    public function Main()
    {
        super();
        this.addEventListener(starling.events.Event.ADDED_TO_STAGE,addToStage);
    }
    private function addToStage(e:starling.events.Event):void
    {
        this.theme = new AeonDesktopTheme( this.stage );
        var quad:Quad = new Quad(stage.stageHeight,stage.stageHeight,0xff0000);
        addChild(quad);

    }
}
}

2 个答案:

答案 0 :(得分:0)

答案在更改方向事件监听器功能中写下此代码:

var viewPort:Rectangle = new Rectangle(0, 0, stage.fullScreenWidth,stage.fullScreenHeight);
Starling.current.viewPort = viewPort;

答案 1 :(得分:0)

Hi this is the code for StartUp file using starling. go through it and replace wtever u are missing.

package
{
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.geom.Rectangle;
    import flash.system.Capabilities;

    import starling.core.Starling;
    import starling.events.TouchPhase;

    //[SWF(width="2048", height="1536", frameRate="60", backgroundColor="0x000000")]//ipad 4th generation Retina
    //[SWF(width="1136", height="640", frameRate="60", backgroundColor="0x000000")]//iphone 5th generation
    //[SWF(width="1024", height="768", frameRate="60", backgroundColor="0x000000")]//ipad
    //[SWF(width="960", height="640", frameRate="60", backgroundColor="0x000000")]//iphone 4th generation
    [SWF(width="480", height="320", frameRate="60", backgroundColor="0x000000")] //iphone 3rd generation

    public class SuperBaby extends Sprite
    { 
        private var mStarling:Starling;

        public function SuperBaby()
        {
            // set general properties

            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;

            Starling.multitouchEnabled = false;  // useful on mobile devices
            Starling.handleLostContext = false; // not necessary on iOS. Saves a lot of memory!

            // create a suitable viewport for the screen size
            var screenWidth:int  = stage.stageWidth;
            var screenHeight:int = stage.stageHeight;
            var viewPort:Rectangle = new Rectangle(0, 0, screenWidth, screenHeight);
            var scaleFactor:uint;
            if(screenHeight < 480){
                scaleFactor = 1;
            }else if(screenHeight>=480){ //&& screenWidth<=640
                scaleFactor = 2;
            }           

            // While Stage3D is initializing, the screen will be blank. To avoid any flickering, 
            // we display a startup image now and remove it below, when Starling is ready to go.

            // launch Starling
            mStarling = new Starling(Mainmenu, stage, viewPort);
            mStarling.simulateMultitouch  = false;
            mStarling.enableErrorChecking = false;


            Mainmenu.GAME_W=mStarling.stage.stageWidth  = uint(screenWidth/scaleFactor);
            Mainmenu.GAME_H=mStarling.stage.stageHeight = uint(screenHeight/scaleFactor);

            mStarling.stage3D.addEventListener(Event.CONTEXT3D_CREATE, function(e:Event):void 
            {
                mStarling.start();
            });




            // When the game becomes inactive, we pause Starling; otherwise, the enter frame event
            // would report a very long 'passedTime' when the app is reactivated. 
        }
    }
}