Weird behaviour with SpriteBatch.Draw in MonoGame
I'm creating a rhythm game. I'm trying to move automatically Notes from upside but something went wrong. Notes just stuck.
Below is code, thanks in advance for help because I don't understand what I'm did bad.
Note.cs:
Below is code, thanks in advance for help because I don't understand what I'm did bad.
c#
public void Update(GameTime gameTime)
{
if (!isInitialized) Initialize(game);
soundEngine.Update();
foreach (var gameplayObject in gameplayObjects)
{
gameplayObject.Update(gameTime, spriteBatch, contentManager);
}
}
public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
{
spriteBatch.Begin();
mainMenuBackground = contentManager.Load<Texture2D>("Background");
pianoTexture = contentManager.Load<Texture2D>("Piano");
spriteBatch.Draw(mainMenuBackground, Vector2.Zero, Color.White);
spriteBatch.Draw(pianoTexture, new Vector2(100, 0), Color.White);
foreach (GameplayObject gameplayObject in gameplayObjects)
{
gameplayObject.Draw(spriteBatch, contentManager);
}
spriteBatch.End();
}c#
public void Update(GameTime gameTime)
{
if (!isInitialized) Initialize(game);
soundEngine.Update();
foreach (var gameplayObject in gameplayObjects)
{
gameplayObject.Update(gameTime, spriteBatch, contentManager);
}
}
public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
{
spriteBatch.Begin();
mainMenuBackground = contentManager.Load<Texture2D>("Background");
pianoTexture = contentManager.Load<Texture2D>("Piano");
spriteBatch.Draw(mainMenuBackground, Vector2.Zero, Color.White);
spriteBatch.Draw(pianoTexture, new Vector2(100, 0), Color.White);
foreach (GameplayObject gameplayObject in gameplayObjects)
{
gameplayObject.Draw(spriteBatch, contentManager);
}
spriteBatch.End();
}Note.cs:
c#
namespace Rhythmical.GameModes.Rhythmical.Tiles
{
public class Note : GameplayObject
{
public float FallSpeed = 50.0f;
private int x;
public Note(int time, int x, int position) : base(time, position)
{
this.Position = position;
this.x = x;
}
public override void Update(GameTime gameTime, SpriteBatch spriteBatch, ContentManager contentManager)
{
float time = (float)(gameTime.TotalGameTime.TotalSeconds);
Position = 100.0f + (float)Math.Sin(time) * 100;
}
public override void Draw(SpriteBatch spriteBatch, ContentManager contentManager)
{
Texture2D noteTexture = contentManager.Load<Texture2D>("NoteTexture");
spriteBatch.Draw(noteTexture, new Vector2(x, Position), Color.White);
}
}
}c#
namespace Rhythmical.GameModes.Rhythmical.Tiles
{
public class Note : GameplayObject
{
public float FallSpeed = 50.0f;
private int x;
public Note(int time, int x, int position) : base(time, position)
{
this.Position = position;
this.x = x;
}
public override void Update(GameTime gameTime, SpriteBatch spriteBatch, ContentManager contentManager)
{
float time = (float)(gameTime.TotalGameTime.TotalSeconds);
Position = 100.0f + (float)Math.Sin(time) * 100;
}
public override void Draw(SpriteBatch spriteBatch, ContentManager contentManager)
{
Texture2D noteTexture = contentManager.Load<Texture2D>("NoteTexture");
spriteBatch.Draw(noteTexture, new Vector2(x, Position), Color.White);
}
}
}