Exemplo n.º 1
0
        /// <summary>
        /// If there is a state change requested during the update loop,
        /// this function handles actual destroying the old state and related processes,
        /// and calls creates on the new state and plugs it into the game object.
        /// </summary>
        protected void switchState()
        {
            FlxG.resetCameras();
            FlxG.resetInput();
            FlxG.destroySounds();
            //FlxG.clearBitmapCache();

            // Clear the debugger overlay's Watch window
            //if(_debugger != null)
            //    _debugger.watch.removeAll();

            // Clear any timers left in the timer manager
            //var timerManager:TimerManager = FlxTimer.manager;
            //if(timerManager != null)
            //    timerManager.clear();

            // Destroy the old state (if there is an old state)
            if (State != null)
            {
                State.destroy();
            }

            // Finally assign and create the new state
            State = RequestedState;
            State.create();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Setup the XNA graphics system and create a new <code>FlxGame</code> from the given arguments;
        /// </summary>
        /// <param name="gameSizeX">The width of your game in game pixels, not necessarily final display pixels (see Zoom).</param>
        /// <param name="gameSizeY">The height of your game in game pixels, not necessarily final display pixels (see Zoom).</param>
        /// <param name="initialState">The class name of the state you want to create and switch to first (e.g. MenuState).</param>
        /// <param name="zoom">The default level of zoom for the game's cameras (e.g. 2 = all pixels are now drawn at 2x). Default = 1.</param>
        /// <param name="gameFramerate">How frequently the game should update (default is 60 times per second).</param>
        /// <param name="flashFramerate">Sets the actual display framerate for Flash player (default is 30 times per second).</param>
        /// <param name="useSystemCursor">Whether to use the default OS mouse pointer, or to use custom flixel ones.</param>
        public FlxGameRunner(
            int gameSizeX,
            int gameSizeY,
            FlxState initialState,
            float zoom           = 1.0f,
            int gameFramerate    = 60,
            int flashFramerate   = 0,
            bool useSystemCursor = false)
        {
            _gameSizeX       = gameSizeX;
            _gameSizeY       = gameSizeY;
            _initialState    = initialState;
            _zoom            = zoom;
            _gameFramerate   = gameFramerate;
            _flashFramerate  = flashFramerate;
            _useSystemCursor = useSystemCursor;

            _screenSizeX      = (int)(_gameSizeX * zoom);
            _screenSizeY      = (int)(_gameSizeY * zoom);
            _outputWindowSize = new Rectangle(0, 0, _screenSizeX, _screenSizeY);

            FlxS.GraphicsDeviceManager = new GraphicsDeviceManager(this);

            // we don't need no new-fangled pixel processing
            // in our retro engine! (xnaFlixel ProTip! ;))
            FlxS.GraphicsDeviceManager.PreferMultiSampling = false;

            FlxS.GraphicsDeviceManager.PreferredBackBufferWidth  = _screenSizeX;
            FlxS.GraphicsDeviceManager.PreferredBackBufferHeight = _screenSizeY;
            FlxS.GraphicsDeviceManager.ApplyChanges();

            Content.RootDirectory = "Content";
            FlxS.ContentManager   = Content;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Instantiate a new game object.
        /// </summary>
        /// <param name="gameSizeX">The width of your game in game pixels, not necessarily final display pixels (see Zoom).</param>
        /// <param name="gameSizeY">The height of your game in game pixels, not necessarily final display pixels (see Zoom).</param>
        /// <param name="initialState">The class name of the state you want to create and switch to first (e.g. MenuState).</param>
        /// <param name="zoom">The default level of zoom for the game's cameras (e.g. 2 = all pixels are now drawn at 2x). Default = 1.</param>
        /// <param name="gameFramerate">How frequently the game should update (default is 60 times per second).</param>
        /// <param name="flashFramerate">Sets the actual display framerate for Flash player (default is 30 times per second).</param>
        /// <param name="useSystemCursor">Whether to use the default OS mouse pointer, or to use custom flixel ones.</param>
        public FlxGame(int gameSizeX,
                       int gameSizeY,
                       FlxState initialState,
                       float zoom           = 1.0f,
                       int gameFramerate    = 60,
                       int flashFramerate   = 0,
                       bool useSystemCursor = false) : base()
        {
            if (flashFramerate != 0)
            {
                throw new NotSupportedException();
            }

            // super high priority init stuff (focus, mouse, etc)
            LostFocus = false;

            /*
             *          _focus = new Sprite();
             *          _focus.visible = false;
             *          _soundTray = new Sprite();
             *          _mouse = new Sprite()
             */

            // flx# - the tight stuff is done in Initialize

            // basic display and update setup stuff
            FlxG.init(this, gameSizeX, gameSizeY, zoom);
            FlxG.Framerate = gameFramerate;
            //FlxG.FlashFramerate = flashFramerate;
            Accumulator     = StepMS;
            Total           = 0;
            State           = null;
            UseSoundHotKeys = true;
            UseSystemCursor = useSystemCursor;

            if (!useSystemCursor)
            {
                //flash.ui.mouse.hide();
            }

            ForceDebugger = false;
            //_debuggerUp = false;

            // replay data

            /*
             * _replay = new FlxReplay();
             * _replayRequested = false;
             * _recordingRequested = false;
             * _replaying = false;
             * _recording = false;
             */

            // then get ready to create the game object for real
            InitialState   = initialState;
            RequestedState = null;
            RequestedReset = true;
            Created        = false;
            //addEventListener(Event.ENTER_FRAME, create);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Setup the XNA graphics system and create a new <code>FlxGame</code> from the given arguments;
        /// </summary>
        /// <param name="gameSizeX">The width of your game in game pixels, not necessarily final display pixels (see Zoom).</param>
        /// <param name="gameSizeY">The height of your game in game pixels, not necessarily final display pixels (see Zoom).</param>
        /// <param name="initialState">The class name of the state you want to create and switch to first (e.g. MenuState).</param>
        /// <param name="zoom">The default level of zoom for the game's cameras (e.g. 2 = all pixels are now drawn at 2x). Default = 1.</param>
        /// <param name="gameFramerate">How frequently the game should update (default is 60 times per second).</param>
        /// <param name="flashFramerate">Sets the actual display framerate for Flash player (default is 30 times per second).</param>
        /// <param name="useSystemCursor">Whether to use the default OS mouse pointer, or to use custom flixel ones.</param>
        public FlxGameRunner(
            int gameSizeX,
            int gameSizeY,
            FlxState initialState,
            float zoom = 1.0f,
            int gameFramerate = 60,
            int flashFramerate = 0,
            bool useSystemCursor = false)
        {
            _gameSizeX = gameSizeX;
            _gameSizeY = gameSizeY;
            _initialState = initialState;
            _zoom = zoom;
            _gameFramerate = gameFramerate;
            _flashFramerate = flashFramerate;
            _useSystemCursor = useSystemCursor;

            _screenSizeX = (int) (_gameSizeX * zoom);
            _screenSizeY = (int) (_gameSizeY * zoom);
            _outputWindowSize = new Rectangle(0, 0, _screenSizeX, _screenSizeY);

            FlxS.GraphicsDeviceManager = new GraphicsDeviceManager(this);

            // we don't need no new-fangled pixel processing
            // in our retro engine! (xnaFlixel ProTip! ;))
            FlxS.GraphicsDeviceManager.PreferMultiSampling = false;

            FlxS.GraphicsDeviceManager.PreferredBackBufferWidth = _screenSizeX;
            FlxS.GraphicsDeviceManager.PreferredBackBufferHeight = _screenSizeY;
            FlxS.GraphicsDeviceManager.ApplyChanges();

            Content.RootDirectory = "Content";
            FlxS.ContentManager = Content;
        }
Exemplo n.º 5
0
        /// <summary>
        /// FlxGame constructor takes in the initial state and resolution of the screen.
        /// </summary>
        /// <param name="State">The state you want to load</param>
        /// <param name="Width">The width of the screen</param>
        /// <param name="Height">The height of the screen</param>
        /// <param name="ContentRootDirectory">The directory of your content.  It is set automatically by default but you can change it if you want to.</param>
        public FlxGame(FlxState State, int Width = 1280, int Height = 720, float Zoom = 1.0f, string ContentRootDirectory = "Content") : base()
        {
            throw new NotSupportedException();

            //FlxG.state = State;

            /*
             * FlxG.zoom = Zoom;
             * graphics = new GraphicsDeviceManager(this);
             * graphics.PreferredBackBufferWidth = Width / (int)Zoom;
             * graphics.PreferredBackBufferHeight = Height / (int)Zoom;
             * graphics.ApplyChanges();
             * Content.RootDirectory = ContentRootDirectory;
             */
        }
Exemplo n.º 6
0
        /// <summary>
        /// If there is a state change requested during the update loop,
        /// this function handles actual destroying the old state and related processes,
        /// and calls creates on the new state and plugs it into the game object.
        /// </summary>
        protected void switchState()
        {
            FlxG.resetCameras();
            FlxG.resetInput();
            FlxG.destroySounds();
            //FlxG.clearBitmapCache();

            // Clear the debugger overlay's Watch window
            //if(_debugger != null)
            //    _debugger.watch.removeAll();

            // Clear any timers left in the timer manager
            //var timerManager:TimerManager = FlxTimer.manager;
            //if(timerManager != null)
            //    timerManager.clear();

            // Destroy the old state (if there is an old state)
            if (State != null)
            {
                State.destroy();
            }

            // Finally assign and create the new state
            State = RequestedState;
            State.create();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Instantiate a new game object.
        /// </summary>
        /// <param name="gameSizeX">The width of your game in game pixels, not necessarily final display pixels (see Zoom).</param>
        /// <param name="gameSizeY">The height of your game in game pixels, not necessarily final display pixels (see Zoom).</param>
        /// <param name="initialState">The class name of the state you want to create and switch to first (e.g. MenuState).</param>
        /// <param name="zoom">The default level of zoom for the game's cameras (e.g. 2 = all pixels are now drawn at 2x). Default = 1.</param>
        /// <param name="gameFramerate">How frequently the game should update (default is 60 times per second).</param>
        /// <param name="flashFramerate">Sets the actual display framerate for Flash player (default is 30 times per second).</param>
        /// <param name="useSystemCursor">Whether to use the default OS mouse pointer, or to use custom flixel ones.</param>
        public FlxGame(int gameSizeX,
                       int gameSizeY,
                       FlxState initialState,
                       float zoom = 1.0f,
                       int gameFramerate = 60,
                       int flashFramerate = 0,
                       bool useSystemCursor = false)
            : base()
        {
            if (flashFramerate != 0)
            {
                throw new NotSupportedException();
            }

            // super high priority init stuff (focus, mouse, etc)
            LostFocus = false;
            /*
            _focus = new Sprite();
            _focus.visible = false;
            _soundTray = new Sprite();
            _mouse = new Sprite()
            */

            // flx# - the tight stuff is done in Initialize

            // basic display and update setup stuff
            FlxG.init(this, gameSizeX, gameSizeY, zoom);
            FlxG.Framerate = gameFramerate;
            //FlxG.FlashFramerate = flashFramerate;
            Accumulator = StepMS;
            Total = 0;
            State = null;
            UseSoundHotKeys = true;
            UseSystemCursor = useSystemCursor;

            if (!useSystemCursor)
            {
                //flash.ui.mouse.hide();
            }

            ForceDebugger = false;
            //_debuggerUp = false;

            // replay data
            /*
            _replay = new FlxReplay();
            _replayRequested = false;
            _recordingRequested = false;
            _replaying = false;
            _recording = false;
            */

            // then get ready to create the game object for real
            InitialState = initialState;
            RequestedState = null;
            RequestedReset = true;
            Created = false;
            //addEventListener(Event.ENTER_FRAME, create);
        }
Exemplo n.º 8
0
        /// <summary>
        /// FlxGame constructor takes in the initial state and resolution of the screen.
        /// </summary>
        /// <param name="State">The state you want to load</param>
        /// <param name="Width">The width of the screen</param>
        /// <param name="Height">The height of the screen</param>
        /// <param name="ContentRootDirectory">The directory of your content.  It is set automatically by default but you can change it if you want to.</param>
        public FlxGame(FlxState State, int Width = 1280, int Height = 720, float Zoom = 1.0f, string ContentRootDirectory = "Content")
            : base()
        {
            throw new NotSupportedException();

            //FlxG.state = State;

            /*
            FlxG.zoom = Zoom;
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferWidth = Width / (int)Zoom;
            graphics.PreferredBackBufferHeight = Height / (int)Zoom;
            graphics.ApplyChanges();
            Content.RootDirectory = ContentRootDirectory;
            */
        }
Exemplo n.º 9
0
        /// <summary>
        /// Load replay data from a string and play it back.
        /// </summary>
        /// <param name="data">The replay that you want to load.</param>
        /// <param name="state">Optional parameter: if you recorded a state-specific demo or cutscene, pass a new instance of that state here.</param>
        /// <param name="cancelKeys">Optional parameter: an array of string names of keys (see FlxKeyboard) that can be pressed to cancel the playback, e.g. ["ESCAPE","ENTER"].  Also accepts 2 custom key names: "ANY" and "MOUSE" (fairly self-explanatory I hope!).</param>
        /// <param name="timeout">Optional parameter: set a time limit for the replay.  CancelKeys will override this if pressed.</param>
        /// <param name="callback">Optional parameter: if set, called when the replay finishes.  Running to the end, CancelKeys, and Timeout will all trigger Callback(), but only once, and CancelKeys and Timeout will NOT call FlxG.stopReplay() if Callback is set!</param>
        public static void loadReplay(String data, FlxState state = null, Array cancelKeys = null, float timeout = 0, Action callback = null)
        {
            throw new NotImplementedException();

            /*
            _game._replay.load(Data);
            if(State == null)
                FlxG.resetGame();
            else
                FlxG.switchState(State);
            _game._replayCancelKeys = CancelKeys;
            _game._replayTimer = Timeout*1000;
            _game._replayCallback = Callback;
            _game._replayRequested = true;
            */
        }
Exemplo n.º 10
0
        /// <summary>
        /// Switch from the current game state to the one specified here.
        /// </summary>
        /// <param name="state">The new state.</param>
        public static void switchState(FlxState state)
        {
            _game.RequestedState = state;

            //state.destroy();
            //state = State;
            //state.create();
        }