checking keyboard events

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.
Locked
2playgames
Posts: 2
Joined: Mon Mar 20, 2006 9:25 pm

checking keyboard events

Post by 2playgames »

hi. i'm quite new to game programming with .NET and C#. I've done some stuff with forms and buttons but this is still a bit hard for me.

so, what i want to do is make the camera move when the players presses a key. i've made these codes:

directly in the class:

Code: Select all

static EventProcesser ep;
event processer class

Code: Select all

public class EventProcesser : Irrlicht.IEventReceiver
	{
		private bool[] keyboard_down;
		
		public EventProcesser()
		{
		}
		
		public bool OnEvent(Event e) {
			if (e.Type == EventType.KeyInput)
			{
				keyboard_down[(int) e.Key] = e.KeyPressedDown;
				return true;
			}
			return false;
		}
		
		public bool KeyDown(KeyCode k) {
			return keyboard_down[(int) k];
		}

	}
// main

Code: Select all

// events
			ep = new EventProcesser();
			device.EventReceiver = ep;
// game loop

Code: Select all

// move the camera
			if(ep.KeyDown(KeyCode.KEY_UP)) { // THIS LINE
				camera_position.Y -= 1;
			}
			if(ep.KeyDown(KeyCode.KEY_DOWN)) {
				camera_position.Y += 1;
			}
however, when i run the game i get an error on the line marked with "THIS LINE"

Exception System.NullReferenceException was thrown in debugee:
Object reference not set to an instance of an object.

anyone care to help an OOP and Irrlicht noob? many thanks in advance

EDIT: on a side note, i don't really understand what 'static' does. i only know that i need to call some of the vars in my main class (e.g. 'device') from other classes directly
Yeurl
Posts: 31
Joined: Thu Apr 13, 2006 9:34 am

Post by Yeurl »

because private bool[] keyboard_down is not initiate
Locked