为什么我的缩放矩阵不起作用?

时间:2014-03-02 03:10:12

标签: c# xna monogame

我正在进行2d塔防。我试图让我的所有图像缩放到屏幕尺寸,但它不起作用。使用此代码的结果是我的背景不会缩放到屏幕,我的塔不会缩放,我认为我的敌人会在屏幕上产生(并且不会缩放)。

矩阵的初始化:

       protected override void Initialize()
        {
            base.Initialize();
            screenscalex = (float)_graphics.GraphicsDevice.Viewport.Width / 1366f;
            screenscaley = (float)_graphics.GraphicsDevice.Viewport.Height / 768f;
            ScalingFactor = new Vector3(screenscalex, screenscaley, 1);
            Global.SpriteScale = Matrix.CreateScale(ScalingFactor);
}

用于精灵类的Draw()(我的塔使用此代码):

   public virtual void Draw(SpriteBatch spriteBatch)
    {
        spriteBatch.End();

        spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, null, Global.SpriteScale);
        spriteBatch.Draw(texture, center, null, Color.White, rotation,
        origin, 1.0f, SpriteEffects.None, 0);
}

为敌人绘制():

    spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, null, Global.SpriteScale);
    if (alive)
    {
        base.Draw(spriteBatch);
    }
    spriteBatch.End();

0 个答案:

没有答案
相关问题