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.
public void Update(GameTime gameTime)
{
gameTime = gameTime;
soundEngine = new SoundEngineXact();
soundEngine.Initialize(game);
keyboardListener = new LowLevelKeyboardListener();
keyboardListener.OnKeyPressed += KeyboardListener_OnKeyPressed;
keyboardListener.HookKeyboard();
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);
spriteBatch.End();
foreach (var gameplayObject in gameplayObjects)
{
gameplayObject.Draw(spriteBatch, contentManager);
}
}
public abstract class GameplayObject
{
public int Time { get; protected set; }
public int Position { get; protected set; }
public GameplayObject(int time, int position)
{
Time = time;
Position = position;
}
public abstract void Update(GameTime gameTime, SpriteBatch spriteBatch, ContentManager contentManager);
public abstract void Draw(SpriteBatch spriteBatch, ContentManager contentManager);
}
public class Note : GameplayObject
{
public float FallSpeed = 100.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 newY = Position + (float)(gameTime.TotalGameTime.TotalSeconds * FallSpeed);
Position = (int)newY;
}
public override void Draw(SpriteBatch spriteBatch, ContentManager contentManager)
{
// Here is something wrong, notes should move dynamically but they don’t
spriteBatch.Begin();
spriteBatch.Draw(contentManager.Load<Texture2D>(“NoteTexture”), new Vector2(x, Position), Color.White);
spriteBatch.End();
}
}