Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Bouncing ball is glitched

$
0
0

I have problem with the bouncing ball, while creating it using class. The ball move but it stuck at the bottom of the page. Please help!!Thank you!!!

The ball move but it stuck at the bottom of the page.

class particle{  constructor(x,y,r){    this.x=x;    this.y=y;    this.r=r;  }  bounce(xSpeed, ySpeed){    this.xSpeed = xSpeed;    this.ySpeed = ySpeed;    if (this.x < 0 || this.x > width) {        this.xSpeed *= -1;    if (this.y < 0 || this.y > height) {        this.ySpeed *= -1;    }    this.x += this.xSpeed;    this.y += this.ySpeed;  }  display(){    fill(0,255,0);    stroke(0);    strokeWeight(1);    circle(this.x,this.y,this.r);  }}let balloon;function setup(){  createCanvas(windowWidth,windowHeight);  balloon = new particle(100, 100, 100);}function draw(){  background(245);  balloon.bounce(5,5);  balloon.display();  }

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>