Реклама на XNA WP7 - PullRequest
       10

Реклама на XNA WP7

2 голосов
/ 30 января 2012
 private void gcw_PositionChanged(object sender, GeoPositionChangedEventArgs 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 = true;
 }

Есть идеи, что вызывает эту ошибку?

 public void CreateAd()
        {
            int width = 480;
            int height = 80;
            int x = (GraphicsDevice.Viewport.Bounds.Width - width) / 2;
            int y = 720;
            bannerAd = adGameComponent.CreateAd(AdUnitId, new Rectangle(x, y, width, height),
              true);
            // Set some visual properties (optional). 
            //bannerAd.BorderEnabled = true; // default is true 
            //bannerAd.BorderColor = Color.White; // default is White 
            //bannerAd.DropShadowEnabled = true; // default is true
            // Provide the location to the ad for better targeting (optional). 
            // This is done by starting a GeoCoordinateWatcher and waiting for the location to 
            // available.
            // The callback will set the location into the ad.
            // Note: The location may not be available in time for the first ad request.
            adGameComponent.Enabled = false;
            this.gcw = new GeoCoordinateWatcher();
            this.gcw.PositionChanged += new
              EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>
              (gcw_PositionChanged);
            this.gcw.Start();
        }

Error   1   Using the generic type 'System.Device.Location.GeoPositionChangedEventArgs<T>' requires 1 type arguments

&&

Ошибка 2 При использовании универсального типа System.Device.Location.GeoPositionChangedEventArgs требуется 1 аргумент типа

Ответы [ 2 ]

2 голосов
/ 31 января 2012

Замените все нижеуказанное на это, и оно будет работать

public void CreateAd()
        {
            // Create a banner ad for the game.
            int width = 480;
            int height = 80;
            int x = (GraphicsDevice.Viewport.Bounds.Width - width) / 2; // centered on the display
            int y = 720;

            bannerAd = adGameComponent.CreateAd(AdUnitId, new Rectangle(x, y, width, height), false);

            // Add handlers for events (optional).
            //nextAd.ErrorOccurred += new EventHandler<Microsoft.Advertising.AdErrorEventArgs>(bannerAd_ErrorOccurred);
            // nextAd.AdRefreshed += new EventHandler(bannerAd_AdRefreshed);

            // Set some visual properties (optional).
            //bannerAd.BorderEnabled = true; // default is true
            //bannerAd.BorderColor = Color.White; // default is White
            //bannerAd.DropShadowEnabled = true; // default is true

            // Provide the location to the ad for better targeting (optional).
            // This is done by starting a GeoCoordinateWatcher and waiting for the location to be available.
            // The callback will set the location into the ad. 
            // Note: The location may not be available in time for the first ad request.
            adGameComponent.Enabled = false;

            this.gcw = new GeoCoordinateWatcher();
            this.gcw.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(gcw_PositionChanged);
            this.gcw.Start();
        }

        public void removeAd()
        {
            // if only running one ad, use this
            adGameComponent.RemoveAd(bannerAd);

            // if running multiple ads, use this
            // adGameComponent.RemoveAll();
        }

        /// <summary>
        /// This is called whenever a new ad is received by the ad client.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bannerAd_AdRefreshed(object sender, EventArgs e)
        {
            Debug.WriteLine("Ad received successfully");
        }

        /// <summary>
        /// This is called when an error occurs during the retrieval of an ad.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">Contains the Error that occurred.</param>
        private void bannerAd_ErrorOccurred(object sender, Microsoft.Advertising.AdErrorEventArgs e)
        {
            Debug.WriteLine("Ad error: " + e.Error.Message);
        }

        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 = true;

            Debug.WriteLine("Device lat/long: " + e.Position.Location.Latitude + ", " + e.Position.Location.Longitude);
        }
2 голосов
/ 30 января 2012

Так я всегда делал.

Объявите формат делегата, все обработчики будут использовать этот формат

public delegate void gcw_PosChangedEventHandler(GeoPositionChangedEventArgs args);

Объявите событие, которое другие могут зарегистрировать для

public event gcw_PosChangedEventHandler gcw_PosChanged;

Зарегистрироваться на событие

someOtherClass.gcw_PosChanged += this.gcw_PositionChanged;

Создайте событие, вызвав его напрямую.

// Inside of 'someOtherClass'
gcw_PosChanged(args);

Обработайте событие, которое мы зарегистрировали за пару шагов ранее.

private void gcw_PositionChanged(GeoPositionChangedEventArgs args)
{
    // 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 = true;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...