Help me to solve my problem(Canvas!)[SOLVED] | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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
14 Respostas
+ 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
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