Concurrent interaction using functions
Mostra commenti meno recenti
I'm coding a program that allows objects to bounce within a window. I have successfully gotten one ball to bounce within it. But when I try to add a second ball, only the first ball moves.
This is the function that allows the object to rebound a wall and it does this indefinitely (While loop) I'm pretty sure the second objcet doesnt show up because the first function is running forever while the while loop is being run (no pun intended). So how do i get the second object to appear and to move concurrently with the first object?
function bounce = bounceFunc(obj, addx,addy,x,y)
%CREATE A FUNCTION OF THIS SO THAT YOU CAN REUSE IT FOR MULTIPLE BALLS
while (x >=0 & x <= 500) & (y >= 0 & y <= 500)
%while the ball is within the window. (extra tolerances???)
%retrieves position for following if statements to determine direction
[x y] = getCenter(obj)
if y >= 480
addy = -addy
end
if y <= 20
addy = -addy
end
if x >= 480
addx = -addx
end
if x <= 20
addx = -addx
end
xMove(obj,addx)
yMove(obj,addy)
redraw
end
end
1 Commento
KSSV
il 16 Nov 2018
functions createWindow and drawBall are missing to check your code.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su 2-D and 3-D Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!