0

I'm doing basic tests on Monogame using Monodevelop as IDE. What I have is a rectangle moving random and always diagonally bouncing against the window boundaries (I'm running the game in window mode). I'm setting a velocity vector but as soon a I set velocity above 60 frames per second the rectangle leaves a noticeable trail. My Motion method is as follows:

public void Move(int elapsedMiliseconds)
{
    this.delta+= elapsedMiliseconds;

    //Remember, I express speed in px/s so I must divide by 1000
    float X = (delta*this.Velocity.X/1000f);
    float Y = (delta*this.Velocity.Y/1000f);

    //Verify that the increment is at least 1px since there's 
    //no such a thing like a half pixel
    //I dont't bother checking 'Y' since Vx and Vy are always equal
    if(X >= 1f)
    {

        //This prevent jerky motion when frames drop down
        //in exchange the movement get slow but at least not jerky
        float maxStepX = this.Velocity.X/60f;
        float maxStepY = this.Velocity.Y/60f;

        X=MathHelper.Clamp(X,0f,maxStepX);
        Y=MathHelper.Clamp(Y,0f,maxStepY);


        //Set new location for the rectangle
        square.X+= (int)(this.DirectionX*X);
        square.Y+= (int)(this.DirectionY*Y);

        this.delta=0;


    }else{

    this.delta+=this.delta;
    }    
}

As I've said, as soon as I get a maxStepX/maxStepY above 2 pixels y get a trail like a faded shadow in the previous position of the square. I'm wondering if it's just a natural visual effect and i have to bear with it or there's something I can do to get rid of that trail. Any hints?

My Draw method is this:

protected override void Draw (GameTime gameTime)
{
        graphics.GraphicsDevice.Clear (Color.Violet);
        spriteBatch.Begin ();
        spriteBatch.Draw(Texture,square,Color.Orange);
        spriteBatch.End ();

        base.Draw (gameTime);
}

If I do a snapshot I just see the screen and the rectangle totally clear (no trail). I've recorded my desktop and it seems that my computer can't handle both the game and the recorder and the output is quite lagged but I can see the trail there and if I play it at slow motion I just see no trail, just the rectangle jumping from one position to another.

EDIT: Ok I got some progress here. Until now I've been using a white pixel as texture to draw rectangles with plain colours but if I use a soccer ball with transparent background as texture there's no trail but it gets blurrier and blurrier as I increase the speed.

Bizcochito
  • 57
  • 1
  • 7
  • 1
    It's probably nothing to do with your Move method. More likely the issue is in the Draw method, maybe not calling graphicsDevice.Clear. Post your Draw method and a screenshot of the problem if you can. – craftworkgames Mar 19 '16 at 20:25
  • It sounds like you're just seeing normal visual artifacts of the monitor. If it goes away when things are slower, and you can't screencap it, it's probably not the code. The fact that you're doing this on top of a solid violet background probably makes it more noticeable. – paste Mar 21 '16 at 20:05
  • That's what I think too, if I use a complex texture there's no trail, even if I use a solid violet background. – Bizcochito Mar 23 '16 at 16:32
  • @Bizcochito: you should set `Graphics.SynchronizeWithVerticalRetrace` to `true` and not go above your monitor vsync refresh rate. It's normal you will see screen tearing otherwise. Also, `elapsedMiliseconds` should be a `float`, not an `int`, if you want to get more accurate results. – vgru Mar 29 '16 at 13:35

0 Answers0