none
TouchPanel.GetState() is preventing DrawableAd to get input

    Question

  • TouchPanel.GetState() is preventing DrawableAd to get input.

    I have TouchPanel.GetState() in my game once in the Update() method...

    I did the implementation for DrawableAdexactly as shwon in the documentation here:

    http://msdn.microsoft.com/en-us/library/advertising-mobile-windows-phone-7-xna-api%28v=msads.20%29.aspx

    So I have an ad displaying which is great, but if I use TouchPanel.GetState() (really needed for my game otherwise cannot play it...) then the ad cannot get any input.

    Someone else has mentioned here having the same problem but that thread is marked as already answered as it was generally just as to where the docs can be found:

    http://community.microsoftadvertising.com/forums/t/72682.aspx?PageIndex=1

    If I move the TouchPanel.GetState() from the Update() into the Draw Function then the Advert does get input, but the game does not receive any TouchLocationState.Pressed nor TouchLocationState.Released and only TouchLocationState.Moved sis coming through, the way my game works this is crucial to have all of the states coming through...

     

    Any ideas?

    Tuesday, March 20, 2012 2:31 PM

All replies

  • To clarify if the base.Update(gameTime); get's called BEFORE the TouchPanel.GetState() then the advert will be able to receive a press and go to the website in the ad. But then the TouchLocationState.Pressed and TouchLocationState.Released do not come through in game as the ad seems to have consumed them and only TouchLocationState.Moved is coming through in the game code.

    However if I press 2 buttons fingers on screen it will get occasiaonally the TouchLocationState.Released but this is not very useful.

    This is how the touches are done then:

    Obtaining TouchCollection once per frame in the Update:

    m_TouchCollection = TouchPanel.GetState();


    then check touch presses, here shown for main menu, in the game it's a bit more complicated but this is my simplest case which doesnt work with the ads enabled:


    foreach (TouchLocation tl in m_TouchCollection)
    {
        TouchLocation prevTL;

        Point prevPoint = new Point(0, 0);
       
        Point curPoint = new Point((int)tl.Position.X, (int)tl.Position.Y);
        if (tl.TryGetPreviousLocation(out prevTL))
        {
            prevPoint = new Point((int)prevTL.Position.X, (int)prevTL.Position.Y);
        }

        for (int ii=0; ii<(int)MainBtn.MAIN_BTN_NUM; ii++)
        {
            int nPrevState = m_MainBtnStates[ii];
            if (GlobalDefines.CheckBtnPress(ref m_MainBtnStates[ii], prevPoint, curPoint, tl.State, m_MainBtnDestRects[ii]) == GlobalDefines.BTN_STATE_RELEASED)
            {

               // Checking m_MainBtnStates[ii] for what to do now

            }

        }

    }

     

    And the CheckBtnPress method which never gets any TouchLocationState.Pressed nor TouchLocationState.Released:

     

    public static int CheckBtnPress(ref int stateBtn, Point prevPoint, Point curPoint, TouchLocationState touchState, Rectangle btnRect)
            {
                int nRet = BTN_STATE_NOACTION;
                if (touchState == TouchLocationState.Invalid)
                {
                    if (stateBtn == 1 &&
                        btnRect.Contains(prevPoint))
                    {
                        stateBtn = 0;
                    }
                }
                else if (touchState == TouchLocationState.Moved)
                {
                    if (stateBtn == 1 &&
                        btnRect.Contains(prevPoint) &&
                        !btnRect.Contains(curPoint))
                    {
                        stateBtn = 0;
                        nRet = BTN_STATE_MOVEDOUT;
                    }
                    else if (btnRect.Contains(curPoint))
                    {
                        stateBtn = 1;
                        nRet = BTN_STATE_MOVEDINTO;
                    }

                }
                else if (touchState == TouchLocationState.Pressed)
                {
                    if (btnRect.Contains(curPoint))
                    {
                        stateBtn = 1;
                        nRet = BTN_STATE_PRESSED;
                    }
                }
                else if (touchState == TouchLocationState.Released)
                {
                    if (stateBtn == 1 &&
                        btnRect.Contains(curPoint))
                    {
                        stateBtn = 0;
                        nRet = BTN_STATE_RELEASED;
                    }
                }
                return nRet;
            }

     

    Wednesday, March 21, 2012 5:46 AM
  • And this is how the Ads done, the InitializeAdvertSystem method is called in the games Initialize, if anyone spots anything wrong let me know, ready to rip my own hair out:)

    #define USING_ADVERTS

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Audio;
    using Microsoft.Xna.Framework.Content;
    using Microsoft.Xna.Framework.GamerServices;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Input;
    using Microsoft.Xna.Framework.Input.Touch;
    using Microsoft.Xna.Framework.Media;
    using System.Diagnostics;
    #if USING_ADVERTS
    using Microsoft.Advertising.Mobile.Xna;
    using System.Device.Location;
    #endif


    namespace Damaged
    {
        /// <summary>
        /// This is the main type for your game
        /// </summary>
        public class Game1 : Microsoft.Xna.Framework.Game
        {

    #if USING_ADVERTS  
            DrawableAd bannerAd;

            // We will use this to find the device location for better ad targeting.

            private GeoCoordinateWatcher gcw = null;

            private void InitializeAdvertSystem()
            {           
                //////////////////////////////////////////////////////////////////////////
                // advert stuff:
    #if DEBUG
                AdGameComponent.Initialize(this, "test_client");
    #else
                AdGameComponent.Initialize(this, "realnumbersblablaprivate");
    #endif

                AdGameComponent.Current.DrawOrderChanged += AdOnDrawOrderChanged;

                Components.Add(AdGameComponent.Current);

                // Create an actual ad for display.
                CreateAd(new Point(5, 5));
                //////////////////////////////////////////////////////////////////////////
            }

            private void CreateAd(Point pt)
            {
                // Create a banner ad for the game.
                int width = 480;
                int height = 80;

    #if DEBUG
                bannerAd = AdGameComponent.Current.CreateAd("Image480_80", new Rectangle(pt.X, pt.Y, width, height), true);
    #else
                bannerAd = AdGameComponent.Current.CreateAd("MyPrivateNumber", new Rectangle(pt.X, pt.Y, width, height), true);
    #endif

                AdGameComponent.Current.Enabled = false;
                this.gcw = new GeoCoordinateWatcher();
                this.gcw.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(gcw_PositionChanged);
                this.gcw.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(gcw_StatusChanged);
                this.gcw.Start();
            }

            private void gcw_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
            {
                // Stop the GeoCoordinateWatcher now that we have the device location.
                this.gcw.Stop();

                bannerAd.LocationLatitude = e.Position.Location.Latitude;
                bannerAd.LocationLongitude = e.Position.Location.Longitude;

                AdGameComponent.Current.Enabled = m_GameStats.IsTrialMode;

                Debug.WriteLine("Device lat/long: " + e.Position.Location.Latitude + ", " + e.Position.Location.Longitude);
            }

            private void gcw_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
            {
                if (e.Status == GeoPositionStatus.Disabled || e.Status == GeoPositionStatus.NoData)
                {
                    // in the case that location services are not enabled or there is no data
                    // enable ads anyway
                    AdGameComponent.Current.Enabled = m_GameStats.IsTrialMode;
                    Debug.WriteLine("GeoCoordinateWatcher Status :" + e.Status);
                }
            }

           
            public void AdOnDrawOrderChanged(object sender, EventArgs args)
            {
                Debug.WriteLine("AdOnDrawOrderChanged");
            }
    #endif // end: #if USING_ADVERTS

     

            protected override void OnActivated(object sender, EventArgs args)
            {
                // check if we are in trial mode:
                if (m_GameStats != null)
                {
    #if DEBUG
                    m_GameStats.IsTrialMode = true;
    #else
                    m_GameStats.IsTrialMode = Guide.IsTrialMode;
    #endif

    #if USING_ADVERTS
                    // ads are enabled/disabled based on if it is on trial mode or not:
                    AdGameComponent.Current.Enabled = m_GameStats.IsTrialMode;
                    // doesn't seem to do anything:
                    //AdGameComponent.Current.UpdateOrder = 10000;
                   
    #endif
                   
                }
            }

    Wednesday, March 21, 2012 6:02 AM
  • This may not be the problem, because I have no problem with what you're talking about. I think it is more likely that you may not have all of the CAPs specified in your WMAppManifest file.
    Thursday, March 22, 2012 4:43 AM
  • that sounds interesting, this is the ones I got:

     

    <Capabilities>
          <Capability Name="ID_CAP_NETWORKING" />
          <Capability Name="ID_CAP_LOCATION" />
          <Capability Name="ID_CAP_SENSORS" />
          <Capability Name="ID_CAP_MICROPHONE" />
          <Capability Name="ID_CAP_MEDIALIB" />
          <Capability Name="ID_CAP_GAMERSERVICES" />
          <Capability Name="ID_CAP_PHONEDIALER" />
          <Capability Name="ID_CAP_PUSH_NOTIFICATION" />
          <Capability Name="ID_CAP_WEBBROWSERCOMPONENT" />
          <Capability Name="ID_CAP_IDENTITY_USER" />
          <Capability Name="ID_CAP_IDENTITY_DEVICE" />

          <!-- Windows Phone OS 7.1 Capabilities -->
          <Capability Name="ID_CAP_ISV_CAMERA" />
          <Capability Name="ID_CAP_CONTACTS" />
          <Capability Name="ID_CAP_APPOINTMENTS" />
        </Capabilities>

    Thursday, March 22, 2012 5:05 AM
  • Did found this: http://msdn.microsoft.com/en-us/library/gg180730%28v=VS.92%29.aspx

    and I have all what it says from test result and more in there. So I removed the unneeded ones.

    But still no luck, thanks anyways, at least all CAPs are correct now:)

    But I got an email from support suggesting to remove the new SDK and install the old SDK.

    Thursday, March 22, 2012 5:52 AM
  • Did this ever get resolved? I'm having the very same issue.
    Saturday, April 07, 2012 8:01 PM
  • Got it working! There's a fix in latest latest sdk download. Be sure base.update() is called 'after' all input is taken care of. Be sure to reboot computer after installing latest latest SDK : )
    Saturday, April 07, 2012 8:29 PM