I am new to MonoGame, I’m making a Pong clone. the ball for some reason seems to have a jerky motion like its skipping frames. I have tried both fixed time step and variable time step. I have turned Vsync on and off. Nothing seems to change, this persists on both PC and android device.
I simply add a velocity vector to the ball’s position (position += velocity * gameTime.ElapsedTime.TotalSeconds).
My game requires the ball to move fast, so I scale the unit velocity vector to 400.
but even with smaller values the results don’t change.
Can some one please tell me what I might be doing wrong?
Actually check this out Note on frame skips and jerkiness even though you’re probably not using BasicEffect, if you’re not disposing other objects correctly/creating alot of them each frame it might cause this. Try moving things like new Rectangle(x,y,width,height) for example to the update loop.
Hi thanks a lot for the reply. That seems to have been the problem. I had and 2 updates called for every draw.
So I’m just going to try to be more careful.
Vector2, Rectangle and other structs containing POD (Plain Old Data) types are fine to “new” as they are allocated on the stack. Classes and boxed types get allocated on the heap which does impact the garbage collector.