problem with keyboard input

Started by
0 comments, last by Pedro Alves 9 years, 8 months ago

i porting my game in xna 4.0 with neoforce to sharpdx with neoforce

the problem it is i can´t put in my game the keyboard input working


 public World(Game game, Manager ola, string text)
            : base(game)
        {

            NeoManager = ola;
           // HandleInput();
         //  Keyboard = new KeyboardManager(game); if uncomment this line say this service is allredy registed
        
            texto = text;
            System.Console.Write(texto);
            //   graphicsDeviceManager.PreferredGraphicsProfile = new FeatureLevel[] { FeatureLevel.Level_9_1, };
            pointer = new PointerManager(game);

          //  keyboarManager = new KeyboardManager(game);
            // this game system has something to draw - enable drawing by default
            // this can be disabled to make objects drawn by this system disappear
            Visible = true;

            // this game system has logic that needs to be updated - enable update by default
            // this can be disabled to simulate a "pause" in logic update
            Enabled = true;
            
            // add the system itself to the systems list, so that it will get initialized and processed properly
            // this can be done after game initialization - the Game class supports adding and removing of game systems dynamically
            Game.GameSystems.Add(this);
            
        }

 private void HandleInput()
        {
            KeyboardState currentKeyboardState =new KeyboardState();
              //  Keyboard.GetState();
     
           

            // Check for exit.


            // Now move the sphere. First, we want to check to see if the sphere should
            // turn. turnAmount will be an accumulation of all the different possible
            // inputs.
            if (currentKeyboardState.IsKeyDown(Keys.A) ||
                currentKeyboardState.IsKeyDown(Keys.Left))
            {
               // turnAmount += 1;
            }
            if (currentKeyboardState.IsKeyDown(Keys.D) ||
                currentKeyboardState.IsKeyDown(Keys.Right))
            {
               // turnAmount -= 1;
            }

            // clamp the turn amount between -1 and 1, and then use the finished
            // value to turn the sphere.
          


            // Next, we want to move the sphere forward or back. to do this, 
            // we'll create a Vector3 and modify use the user's input to modify the Z
            // component, which corresponds to the forward direction.
        

            if (currentKeyboardState.IsKeyDown(Keys.W) ||
                currentKeyboardState.IsKeyDown(Keys.Up))
                
            {
               
            }

            if (currentKeyboardState.IsKeyDown(Keys.S) ||
                currentKeyboardState.IsKeyDown(Keys.Down))
            {
                
            }
            if (currentKeyboardState.IsKeyPressed(Keys.I))
            {
                inventory.Show();


            }
            if (currentKeyboardState.IsKeyDown(Keys.B))
            {
                Charactersstatus.Show();


            }
            /* if (currentKeyboardState.IsKeyDown(Keys.Escape))
             {
                 if(tbc.Focused==true){
                 tbc.Visible = false;
                 }
                 //else
                 //{
                  //   tbc.Show();
                 //}
                
               //  InitConsole(text).Show();
                 //windows();

             }
            */
            // next, we'll create a rotation matrix from the sphereFacingDirection, and
            // use it to transform the vector. If we didn't do this, pressing "up" would
            // always move the ball along +Z. By transforming it, we can move in the
            // direction the sphere is "facing."
          

            // Now we know how much the user wants to move. We'll construct a temporary
            // vector, newSpherePosition, which will represent where the user wants to
            // go. If that value is on the heightmap, we'll allow the move.
          

            // now we need to roll the ball "forward." to do this, we first calculate
            // how far it has moved.
          

            // once we've finished all computations, we can set spherePosition to the
            // new position that we calculated.
       
        }

the error i have is this An unhandled exception of type 'System.NullReferenceException' occurred in TomShane.Neoforce.Central.exe

Additional information: A referência de objecto não foi definida como uma instância de um objecto.

Hello

Advertisement

i find the soluction is very simple only subistute this line for this code


 KeyboardState currentKeyboardState = NeoManager.KeyboardManager.GetState();

i have a another problem when i using the chat press in key i and press key b open a new window i using neoforce to make my game

i want only open a new window or move my character when is not focus in the chat

what happen is en i write in chat we write in console and move my character your open a new window

this is my code


 private void InitConsole(string texto)
        {
            tbc = new TomShane.Neoforce.Controls.TabControl(NeoManager);
            //   tbc.BackColor = new Color(10, 12, 3);
            TomShane.Neoforce.Controls.Console con1 = new TomShane.Neoforce.Controls.Console(NeoManager);
            TomShane.Neoforce.Controls.Console con2 = new TomShane.Neoforce.Controls.Console(NeoManager);


            tbc.Visible = true;
            //  con2.BackColor
            // Setup of TabControl, which will be holding both consoles
            tbc.Init();
            tbc.AddPage("Global");
            tbc.AddPage("Guild");
            tbc.AddPage("PARTY");
            tbc.AddPage("TRADE");

            tbc.Alpha = 220;
            tbc.Left = 0;
            tbc.Height = 220;
            tbc.Width = 450;
            tbc.Top = NeoManager.TargetHeight - tbc.Height - 32;

            tbc.Movable = true;
            tbc.Resizable = true;
            tbc.MinimumHeight = 96;
            tbc.MinimumWidth = 160;

            tbc.TabPages[0].Add(con1);
            tbc.TabPages[1].Add(con2);
            NeoManager.Add(tbc);
            //tbc.StayOnTop = true;
            tbc.TabPages[0].TextColor = new Color(12, 12, 12);
            tbc.TabPages[1].TextColor = new Color(250, 250, 250);
            con1.Init();
            con1.Sender = texto;
            con2.Init();
            con2.Sender = texto;

         


            con2.Width = con1.Width = tbc.TabPages[0].ClientWidth;
            con2.Height = con1.Height = tbc.TabPages[0].ClientHeight;
            con2.Anchor = con1.Anchor = Anchors.All;

            con1.Channels.Add(new ConsoleChannel(0, "General", SharpDX.Color.Orange));
            con1.Channels.Add(new ConsoleChannel(1, "Private", SharpDX.Color.White));
            con1.Channels.Add(new ConsoleChannel(2, "System", SharpDX.Color.Yellow));
            con1.Channels.Add(new ConsoleChannel(3, "Guild", SharpDX.Color.Green));
            con1.Channels.Add(new ConsoleChannel(4, "Trade", SharpDX.Color.Red));

            // We want to share channels and message buffer in both consoles
            con2.Channels = con1.Channels;
            con2.MessageBuffer = con1.MessageBuffer;

            // In the second console we display only "Private" messages
            con2.ChannelFilter.Add(3);

            // Select default channels for each tab
            con1.SelectedChannel = 0;
            con2.SelectedChannel = 3;

            // Do we want to add timestamp or channel name at the start of every message?
            con1.MessageFormat = ConsoleMessageFormats.All;
            con2.MessageFormat = ConsoleMessageFormats.All;


            // Handler for altering incoming message
            con1.MessageSent += new ConsoleMessageEventHandler(con1_MessageSent);

            // We send initial welcome message to System channel
            con1.MessageBuffer.Add(new ConsoleMessage("System", "WELCOME TO THE SERVER! " + texto, 2));

            NeoManager.Add(tbc);
        }
        ////////////////////////////////////////////////////////////////////////////

        ////////////////////////////////////////////////////////////////////////////
        void con1_MessageSent(object sender, ConsoleMessageEventArgs e)
        {
            if (e.Message.Channel == 0)
            {
                //e.Message.Text = "(!) " + e.Message.Text;
            }
        }

the keyboard input its in first post

i call the function


 public override void Update(GameTime gameTime)
        {
          
            HandleInput();
            base.Update(gameTime);

        }

Hello

This topic is closed to new replies.

Advertisement