예제 #1
0
        /**
         * A display object rig to access pan, rotation and zoom actions.
         * @param viewport the starting viewable rectangle including position
         * @param startPosition Point reprsenting the position that the camera will return to on reset
         * @param easingPan The value used to determine how much the camera should move each step towards its target in X and Y.
         * @param easingZoom The value used to determine how much the camera should move each step towards its target for scale.
         * @param easingRotate The value used to determine how much the camera should move each step towards its target for rotation.
         * @param boundingRect A Rectangle that constrains the movement of the camera
         */
        public CameraSprite(Rectangle viewport, Point startPosition = null, float easingPan = 1f, float easingZoom = 1f, float easingRotate = 1, Rectangle boundingRect = null, Juggler juggler = null)
        {
            _juggler = juggler;

            _harness = new Harness();            // The harness is a container to manage rotation, scale and shaking without modifying the pivot and other properties of the main camera.
            _world   = new World(this);

            _viewport = viewport;

            this.startPosition = startPosition;

            _easingPan    = easingPan;
            _easingZoom   = easingZoom;
            _easingRotate = easingRotate;

            if (boundingRect != null)
            {
                this.boundingRect = boundingRect;
            }
            else
            {
                this.boundingRect = NO_BOUNDS.toRectangle();
            }

            _harness.center = new Point(_viewport.x + _viewport.width / 2, _viewport.y + _viewport.height / 2);
            base.addChildAt(_harness, 0);
            _harness.addChild(_world);
        }
예제 #2
0
        public static void Start(uint width, uint height, Type rootType)
        {
            GPUInfo.PrintGPUInfo();
#if DEBUG
            OpenGLDebugCallback.Init();
#endif
            if (rootType == null)
            {
                throw new InvalidOperationException("Root cannot be null!");
            }

            if (Root != null)
            {
                throw new InvalidOperationException("App already initialized!");
            }
            RenderSupport.HasOpenGLError = false;

            Stage          = new Stage(width, height);
            DefaultJuggler = new Juggler();
            Context        = new Context();
            renderSupport  = new RenderSupport();

            Root = (DisplayObject)Activator.CreateInstance(rootType);
            Stage.AddChild(Root);
        }
예제 #3
0
 /// <summary>
 ///
 /// </summary>
 protected virtual void Awake()
 {
     elapsedTime = 0.0f;
     if (asMain)
     {
         if (main == null)
         {
             main = this;
             //Object.DontDestroyOnLoad(main);
         }
     }
 }
예제 #4
0
    /// <summary>
    ///
    /// </summary>
    public virtual void Reset()
    {
        juggler     = null;
        delay       = 0f;
        duration    = 1f;
        repeatCount = k_OneShot;
        call        = null;
        args        = s_EmptyArgs;

        m_IsRunning   = false;
        m_Started     = false;
        m_IsDelay     = false;
        m_StartTime   = 0f;
        m_Duration    = 0f;
        m_RepeatCount = 0;
    }
예제 #5
0
    // Use this for initialization
    void Start()
    {
        if (MovieClipOverlayCameraBehaviour.instance == null)
        {
            return;
        }

        juggler = new Juggler();
        Starling.juggler.add(juggler);

        sAssets         = new AssetManager(1, false);
        sAssets.verbose = true;

        audioService            = AudioService.getInstance();
        audioService.gameObject = this.gameObject;

        stage = MovieClipOverlayCameraBehaviour.instance.stage;
        stage.addEventListener(CEvent.RESIZE, onResize);


        var sWidth     = Screen.width;
        var scaleWidth = sWidth / 640f;

        stage.width  = Screen.width;
        stage.height = Screen.height;

        MovieClipOverlayCameraBehaviour.instance.stageScale.Set(scaleWidth, scaleWidth);

        var tfmc = new MovieClip("flash/fonts_shared.swf:Fonts");

        tfmc.stop();

        // set the default textformat
        var txt = tfmc.getChildByName <TextField>("txt");

        textFormat = txt.textFormat;

        viewManager = new ViewManager(stage);

        assets.enqueue(
            "atlas",
            "atlas_tex"
            );
        assets.loadQueue(AssetManager.Call(assetsProg));
    }
예제 #6
0
 public FrameSprite(Juggler juggler) : base()
 {
     mJuggler = juggler;
 }
예제 #7
0
 void Awake()
 {
     mJuggler = new Juggler();
 }
예제 #8
0
        /// <summary>
        /// Start your app.
        /// </summary>
        /// <param name="width">Stage width</param>
        /// <param name="height">Stage height</param>
        /// <param name="viewportHeight"></param>
        /// <param name="viewportWidth"></param>
        /// <param name="rootType">The root class of your app</param>
        /// <exception cref="InvalidOperationException">When rootType is null or this function is called twice</exception>
        /// <exception cref="NotSupportedException">When the OpenGL framebuffer creation fails.</exception>
        /// <exception cref="ArgumentException">When width or height are less than 32.</exception>
        public static void Start(uint width, uint height, uint viewportWidth, uint viewportHeight, Type rootType)
        {
            Debug.WriteLine("Sparrow starting");
            if (width < 32 || height < 32 || viewportWidth < 32 || viewportHeight < 32)
            {
                throw new ArgumentException($"Invalid dimensions: {width}x{height}");
            }

            var ver = Gl.CurrentVersion;

            if (ver.Api == "gl")
            {
                if (ver.Major < 4)
                {
                    throw new NotSupportedException("You need at least OpenGL 4.0 to run Sparrow!");
                }
            }
            else
            {
                if (ver.Major < 3)
                {
                    throw new NotSupportedException("You need at least OpenGL ES 3.0 to run Sparrow!");
                }
                IsRunningOpenGLES = true;
            }

            Gl.Disable(EnableCap.CullFace);
            Gl.Disable(EnableCap.Dither);

            Gl.Enable(EnableCap.DepthTest);
            Gl.DepthFunc(DepthFunction.Always);

            BlendMode.Get(BlendMode.NORMAL).Activate();

            FramebufferStatus status = Gl.CheckFramebufferStatus(FramebufferTarget.Framebuffer);

            if (status != FramebufferStatus.FramebufferComplete)
            {
                throw new NotSupportedException("GL Framebuffer creation error. Status: " + status);
            }
            _viewPort         = Rectangle.Create(0, 0, viewportWidth, viewportHeight);
            _previousViewPort = Rectangle.Create();
            GPUInfo.PrintGPUInfo();

            // Desktop GL core profile needs a VAO for vertex attrib pointers to work.
            uint vao = Gl.GenVertexArray();

            Gl.BindVertexArray(vao);

            if (rootType == null)
            {
                throw new InvalidOperationException("Root cannot be null!");
            }

            if (Root != null)
            {
                throw new InvalidOperationException("App already initialized!");
            }

            _painter       = new Painter(width, height);
            Stage          = new Stage(width, height);
            DefaultJuggler = new Juggler();

            UpdateViewPort(true);

            Root = (DisplayObject)Activator.CreateInstance(rootType);
            Stage.AddChild(Root);
            _frameId = 1; // starts with 1, so things on the first frame are cached
        }