+ 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

3rd Apr 2021, 10:56 AM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
15 Respuestas
+ 5
Do u know how to do like that ?
3rd Apr 2021, 11:08 AM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 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)
3rd Apr 2021, 11:12 AM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 4
𝕄𝕚𝕔𝕙𝕒𝕖𝕝 𝕃𝕚𝕦 [🄰🄲🅃🄸🅅🄴] (っ◔◡◔)っ Yeah,I want them to appear from the opposite side when hit
3rd Apr 2021, 11:06 AM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 2
So you mean you want the particles to bounce off the screen
3rd Apr 2021, 11:04 AM
Michael
Michael - avatar
+ 2
Oh so you mean when the dot hits the wall it comes from the opposite side
3rd Apr 2021, 11:04 AM
Michael
Michael - avatar
+ 2
Thank you Mirielle[ Exams ] works perfectly as the way I need😇👍
3rd Apr 2021, 7:36 PM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 2
And also thanks LUCARIO🌟
3rd Apr 2021, 7:36 PM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
4th Apr 2021, 4:09 AM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 1
Ok
3rd Apr 2021, 11:07 AM
Michael
Michael - avatar
+ 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)
3rd Apr 2021, 11:09 AM
Michael
Michael - avatar
+ 1
Ok
3rd Apr 2021, 11:23 AM
Michael
Michael - avatar
4th Apr 2021, 12:27 AM
VṢtēphen
VṢtēphen - avatar
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
3rd Apr 2021, 11:26 AM
Vtec Fan
Vtec Fan - avatar
0
Another way: update(){ this.x += this.speedX + canvas.width; this.y += this.speedY + canvas.height; this.x %= canvas.width; this.y %= canvas.height; }
3rd Apr 2021, 9:06 PM
Brian
Brian - avatar