How to go down with an object on the canvas

Asked

Viewed 45 times

1

I’m creating a 1970 game design similar to this: inserir a descrição da imagem aqui

When I ask the canvas to draw the ball down, instead it continues a line like this:

inserir a descrição da imagem aqui

Follows the code:

    ball = {
        xStart: 190,
        xEnd: 15,
        yStart: 200,
        yEnd: 15, 
        speed: 1,

        art: function() {
            ctx.fillStyle = "black"
            ctx.fillRect(this.xStart, this.yStart, this.xEnd, this.yEnd);                
        },

        atualiza: function() {
            var tam =2;
            this.yEnd += this.speed; 
        }
    };

I thought I’d use the shift() but I don’t have much affinity with him and vectors. I did not find a similar problem, if anyone find send me here, thank you who help!!

  • var tam=2; You’re useless, I forgot to erase

  • Are you using some library?

  • no, pure javascript

  • Missed to increase the beginning of the y: this.yStart += this.speed. You want to move, then you have to upgrade the start and end, not only the end, if it will not increase and not move

  • I’ve tried, with that the two parts will go down

  • And not what you want? Both the beginning and the end move down

  • That, but the trail that’s left behind has to be undone, but I can’t access it to erase

  • Before updating x and y try to call yourCanvasRenderingContext2D.clearRect(this.xStart, this.yStart, this.xEnd, this.yEnd) passing the previous coordinates and the size

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.