2012-05-11 63 views
0

我想在我的XNA WP7應用程序中使用廣告控件。它顯示不錯,但我無法點擊它,嘗試使用此代碼:爲XNA WP7應用程序做廣告,無法點擊

public class Game1 : Microsoft.Xna.Framework.Game 
{ 
    GraphicsDeviceManager graphics; 
    SpriteBatch spriteBatch; 

    private DrawableAd bannerAd; 
    private bool shouldDraw; 
    private const string guid = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; // my id is hidden 
    private const string idapp = "00000"; 

    public Game1() 
    { 
     graphics = new GraphicsDeviceManager(this); 
     Content.RootDirectory = "Content"; 
     TargetElapsedTime = TimeSpan.FromTicks(333333); 
     InactiveSleepTime = TimeSpan.FromSeconds(1); 
    } 

    protected override void Initialize() 
    { 
     AdGameComponent.Initialize(this, guid); 
     CreateAd(); 

     Components.Add(AdGameComponent.Current); 
     AdGameComponent.Current.Enabled = true; 
     AdGameComponent.Current.Visible = false; 

     base.Initialize(); 
    } 

    private 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 = 390; 

     bannerAd = AdGameComponent.Current.CreateAd(idapp, new Rectangle(x, y, width, height), true); 
    } 

    protected override void LoadContent() 
    { 
     spriteBatch = new SpriteBatch(GraphicsDevice); 
    } 

    protected override void UnloadContent() 
    { 
    } 

    protected override void Update(GameTime gameTime) 
    { 
     if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) 
      this.Exit(); 

     TouchCollection touchPoints = TouchPanel.GetState(); 
     if (touchPoints.Count > 0) 
     { 
      TouchLocation t = touchPoints[0]; 
      if (t.State == TouchLocationState.Pressed) 
      { 
       shouldDraw = true; 
      } 
     } 


     base.Update(gameTime); 
    } 

    protected override void Draw(GameTime gameTime) 
    { 
     GraphicsDevice.Clear(Color.CornflowerBlue); 

     if (shouldDraw) 
     { 
      shouldDraw = false; 
      AdGameComponent.Current.Visible = true; 
     } 

     base.Draw(gameTime); 
    } 
} 

此代碼有什麼問題?

在此先感謝您的幫助。

問候

注:樣品工作,如果該部件在可視狀態開始,但它不是我想要的,因爲我希望把它不在我的應用程序的啓動

+0

你是什麼意思「無法點擊它」? –

+0

廣告沒有打開瀏覽器,轉發應該 – Tim

+0

有什麼異常?你有沒有Microsoft.Phone.dll在裁判?你在WMAppManifest.xml中是否有Capability Name =「ID_CAP_WEBBROWSERCOMPONENT」 –

回答