0

我正在尝试在我的 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);
    }
}

这段代码有什么问题?

提前感谢您的帮助。

最好的祝福

注意:如果组件以可见状态启动,则示例正在工作,但这不是我想要的,因为我不想把它放在我的应用程序的开头

4

1 回答 1

0

SDK有bug如果我拿最新版本就可以了

请参阅http://community.microsoftadvertising.com/en/developer/pubcenter/f/32/t/72786.aspx

于 2012-05-11T12:35:52.110 回答