+ 4
Animation 1px problem #Solved
So... Ball 20x20. Jumps off from walls each time it touch it,but... It jumps from Y walls <0 coordinate and >380 (works good) But when I'm trying to set same for X - it stuck. Aaaand...I can't get why :D Works only with <0 && >379...but it supposed to be 380 ? Code: https://code.sololearn.com/W3oz311rOExq
11 Réponses
+ 5
...Look like you prefer to use the long code
what I mean is
if (x < 0 || x>380){
speedx *= -1;
} if (y<0 || y>380) {
speedy *= -1;
}
*just replace else if with "if"*
+ 7
if ((x<0 && speedx==-1)||(x>380 && speedx==1))
{speedx *= -1;}
else if ((y<0 && speedy==-1)||(y>380 && speedy==1))
{speedy *= -1;}
+ 7
ya because of red color😵😵
+ 5
change to the conditions above
to also take the current direction into consideration
+ 5
replace "else if"
with just
"if"
That should be worked
After that replace
x=0 with x=100//For working beautifully
+ 5
Btw btw
@Burey is so cool xD
+ 5
nice code
did u saw my code of bouncin ball with marquee
0
@Burey
Yep,that works :)
Changed to
if ((x <=0 && speedx == -1) || (x >= 380 && speedx == 1)) {
speedx *= -1;
} else if ((y <= 0 && speedy == -1) || (y >= 380 && speedy == 1)) {
speedy *= -1;
}
Not sure if it goes out of limits now ,but whatever :D
_____________________
@Very Hard(java & c++ & c# & py & rust & (AllHard))
Thank you,i'll replace it with random positions later:P
- 1
@Very Hard(java & c++ & c# & py & rust & (AllHard))
Not realy ,I tryed to guess the reason of problem first of all...
And guess now I see it.
My first code can't check 2 conditions at once
So after Y bounce - it went in same step to X and instead of bounce kept moving...
So it was like 382 - 381 - 382 ...........untill other Y.
I choised Burey's code cause I thought yours wrong,thought you want me to put X "if" inside Y "if" and for sure I can say it will not work even without tests , that's the reason why I ignored it ,just misunderstood :)
I'm pretty slow at finding real reason :D
- 1
@Prashanth Kumar {ɹəpօɔ}
Nope,post it here if you want to,i'm here from PC ,so I can't check your codes without link :)
- 1
@Prashanth Kumar {ɹəpօɔ}
Fun one,but pretty painfull for eyes :D