1
I’m creating a 1970 game design similar to this:
When I ask the canvas to draw the ball down, instead it continues a line like this:
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– Nycollas
Are you using some library?
– Costamilam
no, pure javascript
– Nycollas
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– Costamilam
I’ve tried, with that the two parts will go down
– Nycollas
And not what you want? Both the beginning and the end move down
– Costamilam
That, but the trail that’s left behind has to be undone, but I can’t access it to erase
– Nycollas
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– Costamilam