简体   繁体   English

AS3,AIR,Starling滑动面板(如MadComponents)

[英]AS3, AIR, Starling sliding panel like MadComponents

I am developing an app using AS3/Air for mobile devices. 我正在使用AS3 / Air开发用于移动设备的应用程序。 I am using Feathers UI and Starling but I would like to create a panel slide (menu, information panel etc) that comes with MadComponents. 我正在使用Feathers UI和Starling,但我想创建MadComponents随附的面板幻灯片(菜单,信息面板等)。 I was considering just creating a class which held the 'panel', import that on to my screen and use Greensock for the tweening. 我当时正在考虑创建一个包含“面板”的类,将其导入到我的屏幕上,并使用Greensock进行补间。

My questions are: 我的问题是:

  1. Would this be the best way using Starling and Feathers? 这是使用史达琳和羽毛的最好方法吗?
  2. Can I use MadComponents with Starling considering it is built using Flash display not Starling? 考虑到它是使用Flash显示器而不是Starling构建的,是否可以将MadComponents与Starling一起使用?
  3. Any other suggestions how I could achieve the same result? 还有其他建议可以达到相同的结果吗?

Basically I just want a button, user clicks the button and the screen tweens left/right and 'opens' the information panel. 基本上,我只想要一个按钮,用户单击该按钮,屏幕将在左右之间进行补间,并“打开”信息面板。 Push the button again and it closes it. 再次按下按钮,它将关闭它。

Many thanks 非常感谢

If I've understood what you've described correctly then it sounds like the ScreenNavigator Class of Feathers is exactly the thing you need? 如果我正确理解了您所描述的内容,那么听起来好像是ScreenNavigator类的羽毛正是您所需要的?

See ScreenNavigator API 请参阅ScreenNavigator API

And the Demo of the Feathers Component Explorer that uses the SlideNavigator in the same way you describe. 以及以您描述的相同方式使用SlideNavigator的Feathers Component Explorer的演示

It looks like Josh Tynjala is looking to add this feature to Feathers: https://github.com/joshtynjala/feathers/issues/527 看起来Josh Tynjala希望将此功能添加到Feathers中: https : //github.com/joshtynjala/feathers/issues/527

In the meantime, I wanted the same thing, so I just whipped this up, and I am happy to share it ( WARNING : Has not been tested extensively): 同时,我想要相同的东西,所以我只想简单地讲一下,很高兴与大家分享( 警告 :未经广泛测试):

package com.hiddenachievement.space.components
{
    import feathers.core.FeathersControl;

    import starling.animation.Transitions;
    import starling.animation.Tween;
    import starling.core.Starling;
    import starling.display.Sprite;

    /**
     * Creates a control that emerges from one side of the stage, while moving the main view to show it.
     */

    public class EdgeSlideControl extends FeathersControl
    {
        private var _mainView:Sprite;
        private var _open:Boolean;
        protected var _tween:Tween;
        protected var _side:int;
        protected var _callback:Function;
        protected var _uncover:Boolean;

        static public const NORTH:int = 0;
        static public const SOUTH:int = 1;
        static public const EAST:int = 2;
        static public const WEST:int = 3;


        /**
         * Creates an EdgeSlideControl.
         *
         * @param mainView The main view (possibly a ScreenNavigator) that will move to show the menu.
         * @param side The side that the control will emerge from.
         * @param uncover When true, the main view will slide away to uncover the control.  When false, the control will slide in from the side, as the main view slides out of the way. 
         *
         */
        public function EdgeSlideControl(mainView:Sprite, side:int, uncover:Boolean = true)
        {
            super();
            _mainView = mainView;
            _side = side;
            _uncover = uncover;
        }

        /**
         * Implements the standard FeathersControl's initialize.
         */
        override protected function initialize():void
        {
            _open = false;
            visible = false;
        }

        /**
         * Begin the animation to display the control.
         */
        public function show(callback:Function=null):void
        {
            _callback = callback;
            _tween = new Tween(_mainView, 0.2, Transitions.LINEAR);
            _tween.onUpdate = updateSlide;
            _tween.onComplete = slideComplete;

            switch(_side)
            {
                case NORTH:
                    _tween.animate("y", height);
                    break;
                case SOUTH:
                    _tween.animate("y", -width);
                    break;
                case EAST:
                    _tween.animate("x", -height);
                    break;
                case WEST:
                    _tween.animate("x", width);
                    break;
            }

            Starling.juggler.add(_tween);
            _open = true;
            visible = true;
        }

        /**
         * Begin the animation to hide the control.
         */     
        public function hide(callback:Function=null):void
        {
            _callback = callback;
            _tween = new Tween(_mainView, 0.2, Transitions.LINEAR);
            _tween.onUpdate = updateSlide;
            _tween.onComplete = slideComplete;

            switch(_side)
            {
                case NORTH:
                case SOUTH:
                    _tween.animate("y", 0);
                    break;
                case EAST:
                case WEST:
                    _tween.animate("x", 0);
                    break;
            }

            Starling.juggler.add(_tween);
            _open = false;
        }


        /**
         * If the control is moving (not in "uncover" mode), move the control into place, next to the main view.
         */         
        public function updateSlide():void
        {
            if (!_uncover)
            {
                switch(_side)
                {
                    case NORTH:
                        y = _mainView.y - height;
                        break;
                    case SOUTH:
                        y = _mainView.height - _mainView.y;
                        break;
                    case EAST:
                        x = _mainView.width - _mainView.x;
                        break;
                    case WEST:
                        x = _mainView.x - width;
                        break;
                }
            }
        }


        /**
         * Perform any actions needed after the transition is done animating.
         */ 
        public function slideComplete():void
        {
            if (_callback != null)
            {
                _callback();    
            }

            visible = _open;
        }

        public function get isOpen():Boolean
        {
            return _open;
        }

    }
}

You may need to add an explicit size to the component, in the direction of the sliding, if it's coming up zero. 您可能需要在滑动方向上向组件添加一个明确的尺寸(如果该尺寸为零)。 Otherwise, the use should be pretty straightforward. 否则,使用应该非常简单。 Let me know if you need any more guidance on how to use it. 让我知道您是否需要更多使用指导。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM