none
Windows Phone 7 Emulator RRS feed

  • Frage

  • Hallo,

    ich habe das Problem, dass ich ein SPiel programmiert hab was mit dem Accelerometer gesteuert wird und das funktioniert soweit sogar suppiduppi ;) aber nun wollte ich einmal einen Screeshot von machen kann aber meine Figur nicht bewegen weil der Elumator nicht auf den Accelerometer Emultor reagiert auch die Tastatursteuerung die ich eingebunden hab wird nicht erkannt. LEdiglich die Touches auf dem Bildschirm die funktionieren wie auf dem Device.

    Kann mir evtl jemand sagen was ich falsch mache, bzw man sagte mir das man irgentwo in den Settings von VS das aktivieren müsste aber leider konnte man mir nicht sagen wo? (das problem tritt übrigensnur bei XNA Apps auf aber nicht bei Silverlight)

    gruß

    Donnerstag, 8. Dezember 2011 16:08

Alle Antworten

  • Hallo,

    es gibt bei CodePlex ein Windows Phone 7 Accelerometer Simulator Kit, siehe auch Windows Phone 7 Emulator: Simulating the accelerometer dazu. 


    Olaf Helper
    * cogito ergo sum * errare humanum est * quote erat demonstrandum *
    Wenn ich denke, ist das ein Fehler und das beweise ich täglich
    Blog Xing
    • Als Antwort vorgeschlagen PeterNowak Donnerstag, 8. Dezember 2011 16:54
    Donnerstag, 8. Dezember 2011 16:49
  • Wenn du den Windows Phone 7.5 Emulator verwendest, hast du eine Emulation des Accelerometers direkt eingebaut.

     

    Gruß, Peter


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Als Antwort vorgeschlagen Horizon_Net Donnerstag, 8. Dezember 2011 22:37
    Donnerstag, 8. Dezember 2011 16:55
  • ich hab das schon mit drin im emulator aber das selbe problem besteht auch bei diesem MS Code example:

    http://create.msdn.com/en-US/sample/accelerometer

    auf dem telefon selbst läuft es perfekt aber im emulator tut sich nichts

    Freitag, 9. Dezember 2011 13:45
  • Hi,

    das ist aber wirklich logisch. Das Sample wurde für das Windows Phone 7 erstellt, wo eine Emulation vom Accelerometer nicht möglich war.

    Deswegen steht in der Klasse Accelerometer auch folgendes:

                if (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Device)            
    
    

    Aus diesem Grund funktioniert es nicht im Emulator...


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Freitag, 9. Dezember 2011 21:18
  • Aber meine Accelerometer Class sieht so aus:

    #region File Description
    //-----------------------------------------------------------------------------
    // Accelerometer.cs
    //
    // Microsoft XNA Community Game Platform
    // Copyright (C) Microsoft Corporation. All rights reserved.
    //-----------------------------------------------------------------------------
    #endregion
    
    #region Using Statements
    using System;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Input;
    #endregion
    
    namespace WindowsPhoneGame7
    {
        /// <summary>
        /// A static encapsulation of accelerometer input to provide games with a polling-based
        /// accelerometer system.
        /// </summary>
        public static class Accelerometer
        {
     
            // the accelerometer sensor on the device
            private static Microsoft.Devices.Sensors.Accelerometer accelerometer = new Microsoft.Devices.Sensors.Accelerometer();
    
            // we need an object for locking because the ReadingChanged event is fired
            // on a different thread than our game
            private static object threadLock = new object();
    
            // we use this to keep the last known value from the accelerometer callback
            private static Vector3 nextValue = new Vector3();
     
    
            // we want to prevent the Accelerometer from being initialized twice.
            private static bool isInitialized = false;
    
            // whether or not the accelerometer is active
            private static bool isActive = false;
    
            /// <summary>
            /// Initializes the Accelerometer for the current game. This method can only be called once per game.
            /// </summary>
            public static void Initialize()
            {
                 //make sure we don't initialize the Accelerometer twice
                if (isInitialized)
                {
                    throw new InvalidOperationException("Initialize can only be called once");
                }
    
     
                // try to start the sensor only on devices, catching the exception if it fails            
                if (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Device)
                {
                    try
                    {
                        accelerometer.ReadingChanged += new EventHandler<Microsoft.Devices.Sensors.AccelerometerReadingEventArgs>(sensor_ReadingChanged);
                        accelerometer.Start();
                        isActive = true;
                    }
                    catch (Microsoft.Devices.Sensors.AccelerometerFailedException)
                    {
                        isActive = false;
                    }
                }
                else
                {
                    // we always return isActive on emulator because we use the arrow
                    // keys for simulation which is always available.
                    isActive = true;
                }
    // 
    
                // remember that we are initialized
                isInitialized = true;
            }
    
     
            private static void sensor_ReadingChanged(object sender, Microsoft.Devices.Sensors.AccelerometerReadingEventArgs e)
            {
                // store the accelerometer value in our variable to be used on the next Update
                lock (threadLock)
                {
                    nextValue = new Vector3((float)e.X, (float)e.Y, (float)e.Z);
                }
            }
     
    
            /// <summary>
            /// Gets the current state of the accelerometer.
            /// </summary>
            /// <returns>A new AccelerometerState with the current state of the accelerometer.</returns>
            public static AccelerometerState GetState()
            {
                // make sure we've initialized the Accelerometer before we try to get the state
                if (!isInitialized)
                {
                    throw new InvalidOperationException("You must Initialize before you can call GetState");
                }
    
                // create a new value for our state
                Vector3 stateValue = new Vector3();
    
     
                // if the accelerometer is active
                if (isActive)
                {
                    if (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Device)
                    {
                        // if we're on device, we'll just grab our latest reading from the accelerometer
                        lock (threadLock)
                        {
                            stateValue = nextValue;
                        }
                    }
                    else
                    {
                        // if we're in the emulator, we'll generate a fake acceleration value using the arrow keys
                        // press the pause/break key to toggle keyboard input for the emulator
                        KeyboardState keyboardState = Keyboard.GetState();
    
                        stateValue.Z = -1;
    
                        if (keyboardState.IsKeyDown(Keys.Left))
                            stateValue.X--;
                        if (keyboardState.IsKeyDown(Keys.Right))
                            stateValue.X++;
                        if (keyboardState.IsKeyDown(Keys.Up))
                            stateValue.Y++;
                        if (keyboardState.IsKeyDown(Keys.Down))
                            stateValue.Y--;
    
                        stateValue.Normalize();
                    }
                }
     
    
                return new AccelerometerState(stateValue, isActive);
            }
        }
    
        /// <summary>
        /// An encapsulation of the accelerometer's current state.
        /// </summary>
        public struct AccelerometerState
        {
            /// <summary>
            /// Gets the accelerometer's current value in G-force.
            /// </summary>
            public Vector3 Acceleration { get; private set; }
    
            /// <summary>
            /// Gets whether or not the accelerometer is active and running.
            /// </summary>
            public bool IsActive { get; private set; }
    
            /// <summary>
            /// Initializes a new AccelerometerState.
            /// </summary>
            /// <param name="acceleration">The current acceleration (in G-force) of the accelerometer.</param>
            /// <param name="isActive">Whether or not the accelerometer is active.</param>
            public AccelerometerState(Vector3 acceleration, bool isActive)
                : this()
            {
                Acceleration = acceleration;
                IsActive = isActive;
            }
    
            /// <summary>
            /// Returns a string containing the values of the Acceleration and IsActive properties.
            /// </summary>
            /// <returns>A new string describing the state.</returns>
            public override string ToString()
            {
                return string.Format("Acceleration: {0}, IsActive: {1}", Acceleration, IsActive);
            }
        }
    }
    
    

    #region File Description
    //-----------------------------------------------------------------------------
    // Accelerometer.cs
    //
    // Microsoft XNA Community Game Platform
    // Copyright (C) Microsoft Corporation. All rights reserved.
    //-----------------------------------------------------------------------------
    #endregion
    
    #region Using Statements
    using System;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Input;
    #endregion
    
    namespace WindowsPhoneGame7
    {
        /// <summary>
        /// A static encapsulation of accelerometer input to provide games with a polling-based
        /// accelerometer system.
        /// </summary>
        public static class Accelerometer
        {
     
            // the accelerometer sensor on the device
            private static Microsoft.Devices.Sensors.Accelerometer accelerometer = new Microsoft.Devices.Sensors.Accelerometer();
    
            // we need an object for locking because the ReadingChanged event is fired
            // on a different thread than our game
            private static object threadLock = new object();
    
            // we use this to keep the last known value from the accelerometer callback
            private static Vector3 nextValue = new Vector3();
     
    
            // we want to prevent the Accelerometer from being initialized twice.
            private static bool isInitialized = false;
    
            // whether or not the accelerometer is active
            private static bool isActive = false;
    
            /// <summary>
            /// Initializes the Accelerometer for the current game. This method can only be called once per game.
            /// </summary>
            public static void Initialize()
            {
                 //make sure we don't initialize the Accelerometer twice
                if (isInitialized)
                {
                    throw new InvalidOperationException("Initialize can only be called once");
                }
    
     
                // try to start the sensor only on devices, catching the exception if it fails            
                if (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Device)
                {
                    try
                    {
                        accelerometer.ReadingChanged += new EventHandler<Microsoft.Devices.Sensors.AccelerometerReadingEventArgs>(sensor_ReadingChanged);
                        accelerometer.Start();
                        isActive = true;
                    }
                    catch (Microsoft.Devices.Sensors.AccelerometerFailedException)
                    {
                        isActive = false;
                    }
                }
                else
                {
                    // we always return isActive on emulator because we use the arrow
                    // keys for simulation which is always available.
                    isActive = true;
                }
    // 
    
                // remember that we are initialized
                isInitialized = true;
            }
    
     
            private static void sensor_ReadingChanged(object sender, Microsoft.Devices.Sensors.AccelerometerReadingEventArgs e)
            {
                // store the accelerometer value in our variable to be used on the next Update
                lock (threadLock)
                {
                    nextValue = new Vector3((float)e.X, (float)e.Y, (float)e.Z);
                }
            }
     
    
            /// <summary>
            /// Gets the current state of the accelerometer.
            /// </summary>
            /// <returns>A new AccelerometerState with the current state of the accelerometer.</returns>
            public static AccelerometerState GetState()
            {
                // make sure we've initialized the Accelerometer before we try to get the state
                if (!isInitialized)
                {
                    throw new InvalidOperationException("You must Initialize before you can call GetState");
                }
    
                // create a new value for our state
                Vector3 stateValue = new Vector3();
    
     
                // if the accelerometer is active
                if (isActive)
                {
                    if (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Device)
                    {
                        // if we're on device, we'll just grab our latest reading from the accelerometer
                        lock (threadLock)
                        {
                            stateValue = nextValue;
                        }
                    }
                    else
                    {
                        // if we're in the emulator, we'll generate a fake acceleration value using the arrow keys
                        // press the pause/break key to toggle keyboard input for the emulator
                        KeyboardState keyboardState = Keyboard.GetState();
    
                        stateValue.Z = -1;
    
                        if (keyboardState.IsKeyDown(Keys.Left))
                            stateValue.X--;
                        if (keyboardState.IsKeyDown(Keys.Right))
                            stateValue.X++;
                        if (keyboardState.IsKeyDown(Keys.Up))
                            stateValue.Y++;
                        if (keyboardState.IsKeyDown(Keys.Down))
                            stateValue.Y--;
    
                        stateValue.Normalize();
                    }
                }
     
    
                return new AccelerometerState(stateValue, isActive);
            }
        }
    
        /// <summary>
        /// An encapsulation of the accelerometer's current state.
        /// </summary>
        public struct AccelerometerState
        {
            /// <summary>
            /// Gets the accelerometer's current value in G-force.
            /// </summary>
            public Vector3 Acceleration { get; private set; }
    
            /// <summary>
            /// Gets whether or not the accelerometer is active and running.
            /// </summary>
            public bool IsActive { get; private set; }
    
            /// <summary>
            /// Initializes a new AccelerometerState.
            /// </summary>
            /// <param name="acceleration">The current acceleration (in G-force) of the accelerometer.</param>
            /// <param name="isActive">Whether or not the accelerometer is active.</param>
            public AccelerometerState(Vector3 acceleration, bool isActive)
                : this()
            {
                Acceleration = acceleration;
                IsActive = isActive;
            }
    
            /// <summary>
            /// Returns a string containing the values of the Acceleration and IsActive properties.
            /// </summary>
            /// <returns>A new string describing the state.</returns>
            public override string ToString()
            {
                return string.Format("Acceleration: {0}, IsActive: {1}", Acceleration, IsActive);
            }
        }
    }
    
    
    und damit müsste doch eigentlich zumindest die tastatursteuerung funktionieren, oder?

    Montag, 12. Dezember 2011 13:35
  • Moin,

     

    warum knallst du den Code doppelt rein?

    Du hast doch oben wieder die Abfrage:

    // try to start the sensor only on devices, catching the exception if it fails            
                if (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Device)

    Debug mal rein und schau, ob er überhaupt in deine initialisierung geht.

    Wenn nicht, kannst ja für deine Screenshots die Abfrage oben rausnehmen.

     

    Und die PC-Tastatur funktioniert meines Wissens nach nicht in WP7 Projekten!

    Montag, 12. Dezember 2011 16:31
  • Entschuldigung das ich die klasse ausversehen 2 mal hier hinein kopiert hatte

     

    aber sowohl der isActive alsauch der isInitialized Status gibt "true" zurück. auch das auskommentieren hat keine besserung gebracht :S

     

    die tastatur funktionier übrigens (jedenfalls auf dem telefon) ;)

    Montag, 12. Dezember 2011 16:58