+ 6
Help me to solve my problem(Canvas!)[SOLVED]
Here is a sample code if mine😇...so in that u could see that the particles are generated randomly and goes to random directions...so I want these particles to be appeared from the opposite side when they pass the screen boundary....what I mean is similar to the snake game,which the snake appears from the opposite side of the screen when gone into passing the screen....so I want that to be included in my code...I have done it but I failed...so pls help me😅😇 https://code.sololearn.com/WPIxk8DfWpn8/?ref=app
15 ответов
+ 5
Do u know how to do like that ?
+ 5
𝕄𝕚𝕔𝕙𝕒𝕖𝕝 𝕃𝕚𝕦 [🄰🄲🅃🄸🅅🄴] (っ◔◡◔)っ I know the theory but I cannot apply it(I make mistakes) :-(
So could you....
Make....
And share😁
(And plus it's better if u could explain it a bit more detail vise)
+ 4
𝕄𝕚𝕔𝕙𝕒𝕖𝕝 𝕃𝕚𝕦 [🄰🄲🅃🄸🅅🄴] (っ◔◡◔)っ Yeah,I want them to appear from the opposite side when hit
+ 2
So you mean you want the particles to bounce off the screen
+ 2
Oh so you mean when the dot hits the wall it comes from the opposite side
+ 2
Thank you Mirielle[ Exams ] works perfectly as the way I need😇👍
+ 2
And also thanks LUCARIO🌟
+ 2
Ok Thank u both ®ụṣ†ƴ Fịŋɠǝɍṣ∅ & Brian
+ 1
Ok
+ 1
Set an if statement in a setInterval function and checks the partical hits 4 sides of wall. You need to do it in 4 if statements and in each if statements if true, you set it appear it (in a loop)
+ 1
Ok
0
I didn't understand question?
This might the solution
this.x += this.speedX;
this.y += this.speedY;
if(this.x>innerWidth){
this.x+=-this.x;
console.log("boundary width finished");
}
if(this.y>innerHeight){
this.y+=-this.y;
console.log("boundary height finished");
}
Also you can write like this🤔
this.x+this.size>innerHeight
0
Another way:
update(){
this.x += this.speedX + canvas.width;
this.y += this.speedY + canvas.height;
this.x %= canvas.width;
this.y %= canvas.height;
}