Is there a way to independently move two objects on a graph?

2 visualizzazioni (ultimi 30 giorni)
Is there a way to have an object constantly moving while other code is being executed.
I am currently working on a basketball game where I would like the hoop to constantly move back and forth using a for loop. Then the ball will shoot when you press a button below is what I have so far. The problem I'm encountering is by nesting the ball for loop inside the hoop for loop, every time the ball integrates through its for loop it pauses the hoop's for loop.
%%Game
game = figure;
set(game,'name','Hoops','numbertitle','off');
clf;
axis([0 10 0 10]);
grid on;
hold on;
ball = plot(1,1,'.','color',[1 .5 0],'MarkerSize',100);
hoop = plot(1,8,'sg','MarkerSize',100);
axis([0 10 0 10]);
while(1)
for j = 1:.02:9
hoop.XData=j;
pause(.00005);
end
for j = 9:-.02:1
hoop.XData=j;
pause(.00005);
end
for i = 1:.050:9
pause(.00025);
a=i*8;
ball.YData=i;
ball.MarkerSize = 100-a;
axis([0 10 0 10]);
end
for i = 9:-.050:7
pause(.00025);
ball.YData=i;
ball.MarkerSize = 100-a;
axis([0 10 0 10]);
end
end
clf('reset');
axis([0 10 0 10]);

Risposte (1)

Walter Roberson
Walter Roberson il 11 Nov 2015
Timer objects.
Note: you cannot actually pause() for less than 0.0001 on any known system. 0.0001 is the timer rate (1 KHz) for the underlying system call for Unix type systems. Windows users generally report not being able to do better than 0.001; on my OS-X system I recently found that I can do between 1 1/4 and 1 1/2 millisecond; see http://uk.mathworks.com/matlabcentral/answers/37716-pause-function-in-matlab-for-1-millisecond#answer_47049

Categorie

Scopri di più su Just for fun in Help Center e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by