Deleting plotted image from a figure if conditions are met
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Daniel Goh
am 11 Dez. 2019
Kommentiert: Daniel Goh
am 12 Dez. 2019
Hi, I am trying to make a game where one progresses vertically upwards by bouncing off platforms and the platforms underneath disappear once they are off the screen. I reckon this should be done by deleting them from the plot, but I don't know how to do this. This is my platform generating loop which makes 50 random platforms:
%Generate platform field
xpf = [];
ypf = [];
platformrecord = [];
for n = 1:1:50
hold on
xpf = [xpf randi(512)];
ypf = [ypf randi(30)];
platformcentre = [xpf(n) ypf(n)+70*(n-1)];
pfgen(48,16);
end
where pfgen() draws the platform image out of a random selection of 4 images, as below
function pfgen(x,y)
%generates a platform at specified x and y coordinates.
global platformcentre
n = randi(4);
d = randi(2);
platforms = [".\Assets\art\bin\simpleplatform-48x16-v1.png"...
".\Assets\art\bin\simpleplatform-48x16-v2.png"...
".\Assets\art\bin\simpleplatform-48x16-v3.png"...
".\Assets\art\bin\simpleplatform-48x16-v4.png"
];
if d == 1
[pfimage, map, alphachannel] = imread(platforms(n));
imagesc('XData',[platformcentre(1)-x/2 platformcentre(1)+x/2], ...
'YData',[platformcentre(2)-y/2 platformcentre(2)+y/2], ...
'CData',flip(pfimage,1), ...
'AlphaData',flip(alphachannel,1));
else
[pfimage, map, alphachannel] = imread(platforms(n));
pfimage = flip(pfimage,1);
alphachannel = flip(alphachannel,1);
imagesc('XData',[platformcentre(1)-x/2 platformcentre(1)+x/2], ...
'YData',[platformcentre(2)-y/2 platformcentre(2)+y/2], ...
'CData',flip(pfimage,2), ...
'AlphaData',flip(alphachannel,2));
end
Is there a way to say if the y-coordinate of my platform is less than the lowest y-coordinate visible, to remove said platform from the plot? Thanks.
0 Kommentare
Akzeptierte Antwort
Philippe Lebel
am 11 Dez. 2019
Bearbeitet: Philippe Lebel
am 11 Dez. 2019
If you get the handle of the plot like so:
h = plot(1,1,'Xr')
you can just delete the handle and the data disapears
delete(h)
like wise for imagesc you can do:
doge = true;
h = imagesc
% wow such image
% very pixel
if doge
delete(h)
end
% such blank
% many empty
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!