Direct X n c# issues with games focus and input...

Started by
-1 comments, last by FoDDa 14 years, 8 months ago
Hi everyone! I recently got a new phone (O2 XDA Zest running Windows Mobile 6 Pro) and decided to try coding a game for it. I've had a lot of experience with c# and direct x so figured it would be a resonably simple process to get most of the coding done. However I've run into a number of issues before I've even got to the main games code lol. My first and main issue, is that I don't seem to be able to get any response from my phones keypad or touch screen. I've tried a number of different methods for capturing the keypresses, but they won't work in my application. The only way I can capture any input, is to put the same code in a new project or to disable my games code post loading the form. When I do the latter, I can detect the navigation keys, but I can't override the others, and my phone reacts as if nothing was running (see below). The second issue, which I suspect could be causing the first, is that my Game doesnt seem to have the current focus. When I press my hardware keys, my phone navigates as if nothing else was running (e.g pressing the Call button too many times will result in me making a phone call even though my games menu is displayed on screen). This also means that my windows home screen flickers through my games menu constantly. A few things to note, I've tried setting the games Focus, KeyPreview and Enabled properties myself when initialising my game. I've tried overriding the default keydown function, as well as assigning event handlers. I think the issue is to do with the way I've setup my applications form and rendering. I started with an empty project (so no default form) and I'm using the standard directx method of rendering my sprites then presenting to the screen. Do I need to interact with the form in some way during this process? Essay over! :) If anyone has come across this issue before, or has an idea about where i'm going wrong, i'd greatly appreciate any help you can provide! Cheers :) p.s, bit of chopped down code to oggle Program.cs

namespace Arsimpe
{
    public class Program
    {
        static void Main()
        {
            Application.Run(new Game());
        }
    }
}




Game.cs

namespace Arsimpe
{
    public partial class Game : Form
    {
        private static Device dx_device;
        private static Sprite dx_spriteBatch;

        public static bool bl_gameRunning = true;

        public Game()
        {
            SystemSettings.ScreenOrientation = ScreenOrientation.Angle90;
            this.KeyPreview = true;
            this.Capture = true;
            this.Enabled = true;
            this.Focus();
            this.ClientSize = new System.Drawing.Size(640, 480);
            this.Text = "Arsimpe v0.01";
            Initialise();
            RunGameLoop();
        }

        public void RunGameLoop()
        {
            do
            {
                Render();
            }
            while (bl_gameRunning);
        }

        public bool Initialise()
        {
            PresentParameters pp_device = new PresentParameters();
            pp_device.Windowed = false;
            pp_device.BackBufferWidth = 640;
            pp_device.BackBufferHeight = 480;
            pp_device.SwapEffect = SwapEffect.Discard;

            dx_device = new Device(0, DeviceType.Default, this, CreateFlags.None, pp_device);
            dx_device.DeviceReset += new System.EventHandler(ResetDevice);
            ResetDevice(dx_device, null);

            Device dx_tempDevice = (Device)sender;

            dx_spriteBatch = new Sprite(dx_tempDevice);

            return true;
        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
	    //Currently calls functions in other classes
	    //And attempts to display a message box
        }

        public static void Render()
        {
            dx_device.Clear(ClearFlags.Target, Color.Black, 0, 0);
            dx_device.BeginScene();

            dx_spriteBatch.Begin(SpriteFlags.AlphaBlend);
            {
		//Renders stuff from other classes
            }
            dx_spriteBatch.End();

            dx_device.EndScene();
            dx_device.Present();
        }

    }
} 






-=FoDDa=-

This topic is closed to new replies.

Advertisement