Can't draw using SpriteBatch

Hello
Faced with an incomprehensible situation for me

There are several components of the game. Depending on the mode, one of the components works. All components are Drawable
When called from the Draw method component, the method executes but nothing is drawn

public override void Draw(GameTime gameTime)
{
    spriteBatch.Begin();
    ...
    spriteBatch.Draw(...)
    ...
    spriteBatch.End();
}

I put a breakpoint, the method is executed, but there is no effect. Can anyone rebuffed with thus already? At least what problem to look for?

If I try to draw my textures in the main Draw() method of the program, then everything turns out. From component-no

What are you trying to draw?

I have a component that contains the following code (the code is not complete)
The Draw() method is called. The instructions are executed, but nothing happens

...
private SpriteBatch _sprite_batch;        
private Texture2D   _static_background;     
...

protected override void LoadContent()
{
    _sprite_batch = new SpriteBatch(GraphicsDevice);
    _static_background = Game.Content.Load<Texture2D>(@"Textures\Home\HomeBackground");
}

public override void Draw(GameTime gameTime)
{
    _sprite_batch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, transformMatrix: _scale_matrix);

    _sprite_batch.Draw(_static_background, Vector2.Zero, new Rectangle(0, 0, _static_background.Width, _static_background.Height), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 1f);

    _sprite_batch.End();
}

Are you coding this on Mac/Linux?

No, I’m using Windows 10, visual studio 2019, monogame 3.7
My code worked before
I added new components and new classes, the old ones did not change

Could I have misused the components? I create all the components in the Game1 class in the Initialize() method and add them to the game before calling base()
At the moment I have about 20 components

Recently faced a problem that when adding a component there was an exception: something like the component is added twice. But I don’t add the same component twice. Could that be the reason?

can we see the code for _scale_matrix setup?

1 Like

Yes, correct. But I’ll check again. When using the same matrix in the Game1 class, the Draw method draws the object correctly

Yes, thank you. I’m an idiot. A matrix is a structure, and I thought it was a class

1 Like