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:
2 Replies
They should move to down
Hi! I'm not a coder chad, but I'll try and help even though I may be totally wrong.
Since the notes do show up. And they don't disappear
it means that they are drawn to screen each frame.
Given this I'd say the problem is in your update loop,
where you set the position of the notes.
Position = 100.0f + (float)Math.Sin(time) * 100;
What I think this line does is:
Set the y position of the note to the result of that equation
but since the equation bases of off a sine wave, it doesn't really go anywhere.
(Might be moving but sorta vibrating) And you use seconds so it would update each second,
might take a while before you see some actual displacement.
I'd say try a really basic thing like Position += 5;
This adds 5 to the y value each update.
And just as a little extra, I'd suggest putting Texture2D noteTexture = contentManager.Load<Texture2D>("NoteTexture");
In the constructor, you really only need to set a texture once. Setting it multiple times like this is a waste of resources.