MOvement...

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.

MOvement...

Postby gopakumator1 » Sat Oct 29, 2005 7:26 pm

Im trying to follow the movement tutorial in c#;
I have created my EventReceiver class;
Now i need to implement it into the Device and have the events execute when a key is pressed, how do i do this?
Here is my Main Class
Code: Select all
public class CarGame
   {
      public static MechEvents MechEvent;
      public static Mech Mech1;
      public static int fps = 0;
      public static Irrlicht.IrrlichtDevice Device;
      public static Map Map1;

      static void Main()
      {
         CarGame.SetUpWorld();
         Map1 = new Map();
         Mech1 = new Mech();
         while(Device.Run())
         {
            CarGame.GameLoop();
         }
      }



      private static void SetUpWorld()
      {
         //Add device
         Device = new IrrlichtDevice(Irrlicht.Video.DriverType.DIRECTX9, new Dimension2D(640,480),32,false, true, false);
         Device.WindowCaption = "CarGame";
         Device.CursorControl.Visible = false;
         Device.EventReceiver = MechEvent;
      }
      private static void UpdateCam()
      {
         Irrlicht.Core.Vector3D MechPosition = CarGame.Mech1.ndMech.Position;
         Vector3D CamPosition;
         CamPosition.X = MechPosition.X-500.0f;
         CamPosition.Y = MechPosition.Y-500.0f;
         CamPosition.Z = 1000f;

         Mech1.MechCam.Position.Set(CamPosition);
         Mech1.MechCam.Target.Set(MechPosition);
      }
      private static void GameLoop()
      {
         CarGame.UpdateCam();
         #region Render
         //Render
         if (Device.WindowActive)
         {
            CarGame.UpdateCam();
            Device.VideoDriver.BeginScene(true,true, new   Color(0,100,100,100));
            Device.SceneManager.DrawAll();
            Device.VideoDriver.EndScene();
         }
         // display frames per second value
         if (fps != Device.VideoDriver.FPS)
         {
            fps = Device.VideoDriver.FPS;
            Device.WindowCaption =
               "Irrlicht.NET C# example 01 - Hello World [" +
               Device.VideoDriver.Name + "] fps:" + fps;   
         }
         #endregion

      }

   }//end class


Here is the Code of My Event Receiver class
[code]
public class MechEvents : Irrlicht.IEventReceiver
{
private static Irrlicht.Core.Vector3D Mech1Pos = new Vector3D();
public MechEvents()
{
}
bool Irrlicht.IEventReceiver.OnEvent(Irrlicht.Event Event)
{
if (Event.Type == Irrlicht.EventType.KeyInput && Event.KeyPressedDown == true)
{
//If The W key is pressed, move Sydney forward
if (Event.Key == Irrlicht.KeyCode.KEY_KEY_W)
{
Mech1Pos = CarGame.Mech1.ndMech.Position;
Mech1Pos.Z +=5;
CarGame.Mech1.ndMech.Position.Set(Mech1Pos);
}
return true;
}
return false;
}
}
[\code]

now where do i go... I don understand it from here on the Movement turorial...
gopakumator1
 

Postby Kikketer » Fri Nov 11, 2005 5:36 am

I'm having the exact same problem. I have the IEventReciever and all that I just can't wrap my head around catching the keypress event in the main.

Someone please help!!!
Kikketer
 

Postby Kikketer » Fri Nov 11, 2005 5:45 am

Sometimes it just takes a second to write it down. I figured out the answer:

In your class that has the main method just put the following:
Code: Select all
 
MyEventReciever myEvent = new MyEventReciever();

... << this is where you declare the IrrlichtDevice device

device.EventReceiver = myEvent;


Then start your main... I just have my IEventReciever output to the console just to see things are working. It was writing, now it's just time for me to figure out how to make things move.
Kikketer
 


Return to Irrlicht.NET

Who is online

Users browsing this forum: No registered users and 0 guests